forked from technoweenie/node-scoped-http-client
/
scoped_get_test.js
34 lines (31 loc) · 1.08 KB
/
scoped_get_test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
var ScopedClient = require('../lib')
, sys = require('sys')
, http = require('http')
, assert = require('assert')
, called = 0
, client
var server = http.createServer(function(req, res) {
res.writeHead(200, {'Content-Type': 'text/plain'})
res.end(req.method + ' ' + req.url + ' -- hello ' + req.headers['accept'])
})
server.listen(9999)
server.addListener('listening', function() {
client = ScopedClient.create('http://localhost:9999',
{headers: {accept: 'text/plain'}})
client.get()(function(err, resp, body) {
called++
assert.equal(200, resp.statusCode)
assert.equal('text/plain', resp.headers['content-type'])
assert.equal('GET / -- hello text/plain', body)
client.path('/a').query('b', '1').get()(function(err, resp, body) {
called++
assert.equal(200, resp.statusCode)
assert.equal('text/plain', resp.headers['content-type'])
assert.equal('GET /a?b=1 -- hello text/plain', body)
server.close()
})
})
})
process.addListener('exit', function() {
assert.equal(2, called)
})