Skip to content

Commit 7320d04

Browse files
committed
Add support for insecureSkipVerify with Node.js native modules
1 parent 7fd160c commit 7320d04

File tree

2 files changed

+38
-1
lines changed

2 files changed

+38
-1
lines changed

src/targets/node/native.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@ module.exports = function (source, options) {
2828
headers: source.allHeaders
2929
}
3030

31+
if (options.insecureSkipVerify) {
32+
reqOpts.rejectUnauthorized = false
33+
}
34+
3135
code.push('const http = require("%s");', source.uriObj.protocol.replace(':', ''))
3236

3337
code.blank()

test/targets/node/native.js

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,36 @@
11
'use strict'
22

3-
module.exports = function (snippet, fixtures) {}
3+
module.exports = function (HTTPSnippet, fixtures) {
4+
it('should support the insecureSkipVerify option', function () {
5+
const result = new HTTPSnippet(fixtures.requests.https).convert('node', 'native', {
6+
insecureSkipVerify: true
7+
})
8+
9+
result.should.be.a.String()
10+
result.should.eql(`const http = require("https");
11+
12+
const options = {
13+
"method": "GET",
14+
"hostname": "mockbin.com",
15+
"port": null,
16+
"path": "/har",
17+
"headers": {},
18+
"rejectUnauthorized": false
19+
};
20+
21+
const req = http.request(options, function (res) {
22+
const chunks = [];
23+
24+
res.on("data", function (chunk) {
25+
chunks.push(chunk);
26+
});
27+
28+
res.on("end", function () {
29+
const body = Buffer.concat(chunks);
30+
console.log(body.toString());
31+
});
32+
});
33+
34+
req.end();`)
35+
})
36+
}

0 commit comments

Comments
 (0)