Skip to content

Commit 9bfb102

Browse files
authored
Merge pull request #249 from vmosyaykin/master
Allow form.submit with url string param to use https
2 parents 2cd7226 + eec0e80 commit 9bfb102

2 files changed

Lines changed: 35 additions & 1 deletion

File tree

lib/form_data.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -394,7 +394,8 @@ FormData.prototype.submit = function(params, cb) {
394394
options = populate({
395395
port: params.port,
396396
path: params.pathname,
397-
host: params.hostname
397+
host: params.hostname,
398+
protocol: params.protocol
398399
}, defaults);
399400

400401
// use custom params
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
var http = require('http');
2+
var https = require('https');
3+
var common = require('../common');
4+
var assert = common.assert;
5+
var FormData = require(common.dir.lib + '/form_data');
6+
7+
/**
8+
* Test url parsing during submission
9+
*/
10+
11+
var req;
12+
var form = new FormData();
13+
form.append('field', 'value');
14+
15+
// Basic parsing
16+
req = form.submit('http://localhost/path', function() {});
17+
assert.strictEqual(req.path, '/path');
18+
assert.ok(req.agent instanceof http.Agent, 'req.agent instanceof http.Agent');
19+
assert.strictEqual(req.getHeader('Host'), 'localhost');
20+
req.abort();
21+
22+
// Non-default port handling
23+
req = form.submit('http://localhost:' + common.port, function() {});
24+
assert.strictEqual(req.getHeader('Host'), 'localhost:' + common.port);
25+
req.abort();
26+
27+
// HTTPS protocol handling
28+
req = form.submit('https://localhost/path', function() {});
29+
assert.ok(req.agent instanceof https.Agent, 'req.agent instanceof https.Agent');
30+
assert.strictEqual(req.getHeader('Host'), 'localhost');
31+
req.abort();
32+
33+

0 commit comments

Comments
 (0)