Skip to content

Commit

Permalink
fix: set protocol correctly (#1027)
Browse files Browse the repository at this point in the history
fixes #976
  • Loading branch information
n30n0v authored and gr2m committed Nov 25, 2017
1 parent ebb8af2 commit fa58493
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
3 changes: 3 additions & 0 deletions lib/request_overrider.js
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,9 @@ function RequestOverrider(req, options, interceptors, remove, cb) {
/// like to change request.path in mid-flight.
options.path = req.path;

// fixes #976
options.protocol = options.proto + ':';

interceptors.forEach(function(interceptor) {
// For correct matching we need to have correct request headers - if these were specified.
setRequestHeaders(req, options, interceptor);
Expand Down
25 changes: 23 additions & 2 deletions tests/test_https_allowunmocked.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@

var test = require('tap').test;
var mikealRequest = require('request');
var nock = require('../');

nock.enableNetConnect();

test('allowUnmocked for https', {skip: process.env.AIRPLANE}, function(t) {
var nock = require('../');
nock.enableNetConnect();
nock('https://www.google.com/', {allowUnmocked: true})
.get('/pathneverhit')
.reply(200, {foo: 'bar'});
Expand All @@ -22,3 +23,23 @@ test('allowUnmocked for https', {skip: process.env.AIRPLANE}, function(t) {
t.end();
});
});

test('allowUnmocked for https with query test miss', {skip: process.env.AIRPLANE}, function(t) {
nock.cleanAll();
nock('https://www.google.com', {allowUnmocked: true})
.get('/search')
.query(function() {return false;})
.reply(500);

var options = {
method: 'GET',
uri: 'https://www.google.com/search'
};

mikealRequest(options, function(err, resp, body) {
t.notOk(err, 'should be no error');
t.true(typeof body !== 'undefined', 'body should not be undefined');
t.true(body.length !== 0, 'body should not be empty');
t.end();
});
});

0 comments on commit fa58493

Please sign in to comment.