-
-
Notifications
You must be signed in to change notification settings - Fork 100
Allow passthrough redirects #125
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,9 @@ | ||
'use strict' | ||
|
||
const From = require('fastify-reply-from') | ||
const WebSocket = require('ws') | ||
|
||
const httpMethods = ['DELETE', 'GET', 'HEAD', 'PATCH', 'POST', 'PUT', 'OPTIONS'] | ||
const urlPattern = /^https?:\/\// | ||
|
||
function liftErrorCode (code) { | ||
if (typeof code !== 'number') { | ||
|
@@ -31,6 +31,10 @@ function waitConnection (socket, write) { | |
} | ||
} | ||
|
||
function isExternalUrl (url = '') { | ||
return urlPattern.test(url) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How is this guaranteed to be "an external url"? Shouldn't the headers be inspected to determine if there is a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That was my initial thought but There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Then I would think the solution starts with resolving that issue. I do not see how this simple test is a guarantee of a redirect. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If |
||
}; | ||
|
||
function proxyWebSockets (source, target) { | ||
function close (code, reason) { | ||
closeWebSocket(source, code, reason) | ||
|
@@ -125,7 +129,7 @@ async function httpProxy (fastify, opts) { | |
|
||
function rewriteHeaders (headers) { | ||
const location = headers.location | ||
if (location) { | ||
if (location && !isExternalUrl(location)) { | ||
headers.location = location.replace(rewritePrefix, fastify.prefix) | ||
} | ||
if (oldRewriteHeaders) { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would you mind to check if
url.startsWith('http://') || url.startsWith('https://')
is faster than regex?