Skip to content

Commit b90ab88

Browse files
committed
Allow non proxy redirects when options.proxy = false
1 parent e02a1bb commit b90ab88

2 files changed

Lines changed: 19 additions & 1 deletion

File tree

index.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,11 @@
22

33
exports.register = function (server, options, next) {
44
server.ext('onRequest', function (request, reply) {
5-
if (request.headers['x-forwarded-proto'] === 'http') {
5+
var redirect = options.proxy !== false
6+
? request.headers['x-forwarded-proto'] === 'http'
7+
: request.server.info.protocol === 'http'
8+
9+
if (redirect) {
610
return reply()
711
.redirect('https://' + request.headers.host + request.url.path)
812
.code(301)

test.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,20 @@ test('proxied requests', function (t) {
1919
})
2020
})
2121

22+
test('un-proxied requests: options = {proxy: false}', function (t) {
23+
t.plan(2)
24+
25+
Server({proxy: false}).inject({
26+
url: '/',
27+
headers: {
28+
host: 'host'
29+
}
30+
}, function (response) {
31+
t.equal(response.statusCode, 301, 'sets 301 code')
32+
t.equal(response.headers.location, 'https://host/', 'sets Location header')
33+
})
34+
})
35+
2236
test('query string', function (t) {
2337
t.plan(2)
2438

0 commit comments

Comments
 (0)