22c5d98537447ccd78f83f985cca94abfee33243.svn-base
920 Bytes
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
35
36
37
38
39
var server = require('./server')
, events = require('events')
, stream = require('stream')
, assert = require('assert')
, fs = require('fs')
, request = require('../main.js')
, path = require('path')
, util = require('util')
;
var port = 6768
, called = false
, proxiedHost = 'google.com'
;
var s = server.createServer(port)
s.listen(port, function () {
s.on('http://google.com/', function (req, res) {
called = true
assert.equal(req.headers.host, proxiedHost)
res.writeHeader(200)
res.end()
})
request ({
url: 'http://'+proxiedHost,
proxy: 'http://localhost:'+port
/*
//should behave as if these arguments where passed:
url: 'http://localhost:'+port,
headers: {host: proxiedHost}
//*/
}, function (err, res, body) {
s.close()
})
})
process.on('exit', function () {
assert.ok(called, 'the request must be made to the proxy server')
})