This repository has been archived by the owner on Mar 8, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
tools/parseURL: correctly preserve port
- Loading branch information
Showing
2 changed files
with
64 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}); | ||
}); |