forked from request/request
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtest-proxy-connect.js
More file actions
88 lines (82 loc) · 2.23 KB
/
Copy pathtest-proxy-connect.js
File metadata and controls
88 lines (82 loc) · 2.23 KB
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
84
85
86
87
88
var server = require('./server')
, events = require('events')
, stream = require('stream')
, assert = require('assert')
, fs = require('fs')
, request = require('../index')
, path = require('path')
, util = require('util')
;
var port = 6768
, called = false
, proxiedHost = 'google.com'
, expectProxyHeaders = {
accept: 'yo',
'user-agent': 'just another foobar',
host: 'google.com'
}
, data = ""
, expect =
"CONNECT google.com:80 HTTP/1.1\r\n" +
"accept: yo\r\n" +
"user-agent: just another foobar\r\n" +
"host: google.com:80\r\n" +
"Proxy-Authorization: Basic dXNlcjpwYXNz\r\n" +
"Connection: close\r\n" +
"\r\n" +
"GET / HTTP/1.1\r\n" +
"authorization: Token deadbeef\r\n" +
"do-not-send-this: ok\r\n" +
"accept: yo\r\n" +
"user-agent: just another foobar\r\n" +
"host: google.com\r\n" +
"Connection: keep-alive\r\n" +
"\r\n"
;
var s = require('net').createServer(function (sock) {
s.close()
called = true
sock.once("data", function (c) {
console.error("server got data")
// process.stderr.write(c)
data += c
sock.write("HTTP/1.1 200 OK\r\n\r\n")
sock.once("data", function (c) {
console.error("server got data again")
// process.stderr.write(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")
})
})
})
s.listen(port, function () {
request ({
tunnel: true,
url: 'http://'+proxiedHost,
proxy: 'http://localhost:'+port,
headers: {
'Proxy-Authorization': 'Basic dXNlcjpwYXNz',
authorization: 'Token deadbeef',
'do-not-send-this': 'ok',
accept: 'yo',
'user-agent': 'just another foobar'
}
/*
//should behave as if these arguments where passed:
url: 'http://localhost:'+port,
headers: {host: proxiedHost}
//*/
}, function (err, res, body) {
gotResp = true
assert.equal(body, "derp\n")
assert.equal(data, expect)
}).end()
})
process.on('exit', function () {
assert.ok(called, 'the request must be made to the proxy server')
assert.ok(gotResp, "got request")
})