Skip to content
This repository has been archived by the owner on Mar 8, 2023. It is now read-only.

Commit

Permalink
tools/parseURL: correctly preserve port
Browse files Browse the repository at this point in the history
  • Loading branch information
skenqbx committed Oct 21, 2015
1 parent a15bec1 commit 6b8c1e6
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/tools.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ function parseURL(url) {
return {
proto: parsed.protocol.substr(0, parsed.protocol.length - 1),
host: parsed.hostname,
port: parsed.port ? parseInt(parsed.port, 10) : undefined,
port: parsed.port ? parseInt(parsed.port, 10) : null,
path: parsed.path
};
}
Expand Down
63 changes: 63 additions & 0 deletions test/test-http-https-redirect.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
'use strict';
/* global suite: false, setup: false, test: false,
teardown: false, suiteSetup: false, suiteTeardown: false */
var assert = require('assert');
var common = require('./common');
var http = require('http');
var RAIL = require('../');


suite('http:https:redirect', function() {
var rail, httpServer;
var onHTTPrequest;

function httpListener(request, response) {
if (typeof onHTTPrequest === 'function') {
onHTTPrequest(request, response);
}
}


suiteSetup(function(done) {
rail = new RAIL({
proto: 'http',
request: {
port: common.port,
rejectUnauthorized: false
}
});

rail.use('redirect');
rail.use('buffer', {default: true});

httpServer = http.createServer(httpListener);
httpServer.listen(common.port, done);
});


test('upgrade http to https', function(done) {
onHTTPrequest = function(request, response) {
assert.strictEqual(request.url, '/home/test');

response.writeHead(302, {
Location: 'https://duckduckgo.com/'
});

response.end();
};

rail.call({
path: '/home/test'
}, function(response) {
assert.strictEqual(response.statusCode, 200);
done();
}).on('redirect', function(options) {
assert.strictEqual(options.request.port, 443);
}).end();
});


suiteTeardown(function(done) {
httpServer.close(done);
});
});

0 comments on commit 6b8c1e6

Please sign in to comment.