Skip to content

Commit

Permalink
Fix weird error
Browse files Browse the repository at this point in the history
  • Loading branch information
watson committed Oct 26, 2020
1 parent 74622fc commit 4180378
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion src/core/server/http/lifecycle/on_pre_routing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,25 @@ export function adoptToHapiOnRequest(fn: OnPreRoutingHandler, log: Logger) {
appState.rewrittenUrl ?? new URL(request.url.href!, request._core.info.uri);

const { url } = result;
request.setUrl(url);

// TODO: Remove once we upgrade to Node.js 12!
//
// Warning: The following for-loop took 10 days to write, and is a hack
// to force V8 to make a copy of the string in memory.
//
// The reason why we need this is because of what appears to be a bug
// in V8 that caused some URL paths to not be routed correctly once
// `request.setUrl` was called with the path.
//
// The details can be seen in this discussion on Twitter:
// https://twitter.com/wa7son/status/1319992632366518277
let urlCopy = '';
for (let i = 0; i < url.length; i++) {
urlCopy += url[i];
}

request.setUrl(urlCopy);

// We should update raw request as well since it can be proxied to the old platform
request.raw.req.url = url;
return responseToolkit.continue;
Expand Down

0 comments on commit 4180378

Please sign in to comment.