|
1 | 1 | var common = require('../common'); |
2 | 2 | var assert = common.assert; |
3 | 3 | var FormData = require(common.dir.lib + '/form_data'); |
4 | | -var correctSocket = 'npmjs.org:443'; |
5 | 4 |
|
6 | 5 | // testing default https port |
7 | 6 |
|
8 | 7 | // check params as string |
9 | | -testRequest('https://npmjs.org/'); |
| 8 | +testRequest('https://localhost:'+common.httpsPort+'/'); |
10 | 9 |
|
11 | 10 | // check params as object |
12 | | -testRequest({protocol: 'https:', hostname: 'npmjs.org', pathname: '/'}); |
| 11 | +testRequest({protocol: 'https:', hostname: 'localhost', port: common.httpsPort, pathname: '/'}); |
13 | 12 |
|
14 | 13 | // --- Santa's little helpers |
15 | 14 |
|
16 | 15 | function testRequest(params) |
17 | 16 | { |
18 | 17 | var form; |
19 | | - var request; |
20 | | - var sockets; |
21 | 18 |
|
22 | 19 | form = new FormData(); |
23 | 20 |
|
24 | | - // break getLength – prevent submit() from actually submitting |
25 | | - form.getLength = function(){}; |
| 21 | + form.submit(params, function(err, res) |
| 22 | + { |
| 23 | + if (err) { |
| 24 | + throw err; |
| 25 | + } |
26 | 26 |
|
27 | | - request = form.submit(params); |
| 27 | + assert.strictEqual(res.statusCode, 200); |
| 28 | + assert.strictEqual(res.headers['x-success'], 'OK'); |
28 | 29 |
|
29 | | - sockets = Object.keys(request.agent.sockets); |
30 | | - |
31 | | - assert.equal(sockets.length, 1); |
32 | | - |
33 | | - // in 0.10 it's "nodomain:443" |
34 | | - // in 0.11 it's "nodomain:443::::::::" |
35 | | - assert.equal(correctSocket, sockets[0].substr(0, correctSocket.length)); |
36 | | - |
37 | | - // stop here |
38 | | - request.abort(); |
39 | | - |
40 | | - request.on('error', function(err){ |
41 | | - assert.equal(err.code, 'ECONNRESET'); |
| 30 | + // unstuck new streams |
| 31 | + res.resume(); |
42 | 32 | }); |
43 | 33 |
|
44 | | - return request; |
45 | 34 | } |
0 commit comments