Comparing version 0.5.7 to 0.6.0
var path = require('path') | ||
, http = require('http') | ||
, https = require('https') | ||
, url = require('url') | ||
@@ -341,2 +342,17 @@ , EventEmitter = require('events').EventEmitter; | ||
var httpsRequest = https.request; | ||
https.request = function(options, callback) { | ||
var basePath = 'https://' + options.host | ||
, interceptors = allInterceptors[basePath]; | ||
options.https = true; | ||
if (interceptors && interceptors.length > 0) { | ||
return processRequest(interceptors, options, callback); | ||
} else { | ||
return httpRequest.apply(http, arguments); | ||
} | ||
}; | ||
module.exports = addGlobalInterceptor; |
@@ -67,3 +67,4 @@ var path = require('path') | ||
, path = options.path | ||
, matches; | ||
, matches | ||
, proto = options.https ? 'https': 'http'; | ||
@@ -75,3 +76,3 @@ if (transformPathFunction) { path = transformPathFunction(path); } | ||
if (transformRequestBodyFunction) { body = transformRequestBodyFunction(body); } | ||
var matchKey = method + ' http://' + options.host + path; | ||
var matchKey = method + ' ' + proto + '://' + options.host + path; | ||
if (body) { matchKey += (' ' + body); } | ||
@@ -78,0 +79,0 @@ matches = matchKey === this._key; |
{ "name" : "nock" | ||
, "description" : "HTTP Server mocking for Node.js" | ||
, "tags" : ["Mock", "HTTP", "testing", "isolation"] | ||
, "version" : "0.5.7" | ||
, "version" : "0.6.0" | ||
, "author" : "Pedro Teixeira <pedro.teixeira@gmail.com>" | ||
@@ -6,0 +6,0 @@ , "contributors" : |
var nock = require('../.') | ||
var http = require('http'); | ||
var https = require('https'); | ||
var util = require('util'); | ||
@@ -806,1 +807,28 @@ var events = require('events'); | ||
}); | ||
tap.test("can use https", function(t) { | ||
var dataCalled = false | ||
var scope = nock('https://google.com') | ||
.get('/') | ||
.reply(200, "Hello World!"); | ||
var req = https.request({ | ||
host: "google.com" | ||
, path: '/' | ||
}, function(res) { | ||
t.equal(res.statusCode, 200); | ||
res.on('end', function() { | ||
t.ok(dataCalled); | ||
scope.done(); | ||
t.end(); | ||
}); | ||
res.on('data', function(data) { | ||
dataCalled = true; | ||
t.ok(data instanceof Buffer, "data should be buffer"); | ||
t.equal(data.toString(), "Hello World!", "response should match"); | ||
}); | ||
}); | ||
req.end(); | ||
}); |
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
43029
1239
6