fs: report correct path when EEXIST
[platform/upstream/nodejs.git] / deps / npm / node_modules / request / tests / test-piped-redirect.js
1 var http = require('http')
2   , assert = require('assert')
3   , request = require('../index')
4   ;
5
6 var portOne = 8968
7   , portTwo = 8969
8   ;
9
10
11 // server one
12 var s1 = http.createServer(function (req, resp) {
13   if (req.url == '/original') {
14     resp.writeHeader(302, {'location': '/redirected'})
15     resp.end()
16   } else if (req.url == '/redirected') {
17     resp.writeHeader(200, {'content-type': 'text/plain'})
18     resp.write('OK')
19     resp.end()
20   }
21
22 }).listen(portOne);
23
24
25 // server two
26 var s2 = http.createServer(function (req, resp) {
27   var x = request('http://localhost:'+portOne+'/original')
28   req.pipe(x)
29   x.pipe(resp)
30
31 }).listen(portTwo, function () {
32   var r = request('http://localhost:'+portTwo+'/original', function (err, res, body) {
33     assert.equal(body, 'OK')
34
35     s1.close()
36     s2.close()
37   });
38
39   // it hangs, so wait a second :)
40   r.timeout = 1000;
41
42 })