forked from request/request
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest-piped-redirect.js
More file actions
42 lines (32 loc) · 868 Bytes
/
Copy pathtest-piped-redirect.js
File metadata and controls
42 lines (32 loc) · 868 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
40
41
42
var http = require('http')
, assert = require('assert')
, request = require('../index')
;
var portOne = 8968
, portTwo = 8969
;
// server one
var s1 = http.createServer(function (req, resp) {
if (req.url == '/original') {
resp.writeHeader(302, {'location': '/redirected'})
resp.end()
} else if (req.url == '/redirected') {
resp.writeHeader(200, {'content-type': 'text/plain'})
resp.write('OK')
resp.end()
}
}).listen(portOne);
// server two
var s2 = http.createServer(function (req, resp) {
var x = request('http://localhost:'+portOne+'/original')
req.pipe(x)
x.pipe(resp)
}).listen(portTwo, function () {
var r = request('http://localhost:'+portTwo+'/original', function (err, res, body) {
assert.equal(body, 'OK')
s1.close()
s2.close()
});
// it hangs, so wait a second :)
r.timeout = 1000;
})