-
Notifications
You must be signed in to change notification settings - Fork 3.1k
/
test-proxy-connect.js
83 lines (74 loc) 路 1.9 KB
/
test-proxy-connect.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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
'use strict'
var net = require('net')
, request = require('../index')
, tape = require('tape')
var port = 6768
, called = false
, proxiedHost = 'google.com'
, data = ''
var s = require('net').createServer(function(sock) {
called = true
sock.once('data', function (c) {
data += c
sock.write('HTTP/1.1 200 OK\r\n\r\n')
sock.once('data', function (c) {
data += c
sock.write('HTTP/1.1 200 OK\r\n')
sock.write('content-type: text/plain\r\n')
sock.write('content-length: 5\r\n')
sock.write('\r\n')
sock.end('derp\n')
})
})
})
tape('setup', function(t) {
s.listen(port, function() {
t.end()
})
})
tape('proxy', function(t) {
request({
tunnel: true,
url: 'http://' + proxiedHost,
proxy: 'http://localhost:' + port,
headers: {
'Proxy-Authorization' : 'Basic dXNlcjpwYXNz',
'authorization' : 'Token deadbeef',
'dont-send-to-proxy' : 'ok',
'dont-send-to-dest' : 'ok',
'accept' : 'yo',
'user-agent' : 'just another foobar'
},
proxyHeaderExclusiveList: ['Dont-send-to-dest']
}, function(err, res, body) {
t.equal(err, null)
t.equal(res.statusCode, 200)
t.equal(body, 'derp\n')
t.equal(data, [
'CONNECT google.com:80 HTTP/1.1',
'Proxy-Authorization: Basic dXNlcjpwYXNz',
'dont-send-to-dest: ok',
'accept: yo',
'user-agent: just another foobar',
'host: google.com:80',
'Connection: close',
'',
'GET / HTTP/1.1',
'authorization: Token deadbeef',
'dont-send-to-proxy: ok',
'accept: yo',
'user-agent: just another foobar',
'host: google.com',
'Connection: keep-alive',
'',
''
].join('\r\n'))
t.equal(called, true, 'the request must be made to the proxy server')
t.end()
})
})
tape('cleanup', function(t) {
s.close(function() {
t.end()
})
})