Skip to content
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

decouple MF-Original-URL header from disabling the pretty-error page #689

Merged
merged 2 commits into from
Oct 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/miniflare/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1155,6 +1155,7 @@ export class Miniflare {
const forward = new Request(input, init);
const url = new URL(forward.url);
forward.headers.set(CoreHeaders.ORIGINAL_URL, url.toString());
forward.headers.set(CoreHeaders.DISABLE_PRETTY_ERROR, "true");
url.protocol = this.#runtimeEntryURL.protocol;
url.host = this.#runtimeEntryURL.host;
if (forward.cf) {
Expand Down
1 change: 1 addition & 0 deletions packages/miniflare/src/workers/core/constants.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
export const CoreHeaders = {
CUSTOM_SERVICE: "MF-Custom-Service",
ORIGINAL_URL: "MF-Original-URL",
DISABLE_PRETTY_ERROR: "MF-Disable-Pretty-Error",
ERROR_STACK: "MF-Experimental-Error-Stack",
ROUTE_OVERRIDE: "MF-Route-Override",

Expand Down
9 changes: 5 additions & 4 deletions packages/miniflare/src/workers/core/entry.worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ function getUserRequest(
request = new Request(request, { cf: env[CoreBindings.JSON_CF_BLOB] });
}
request.headers.delete(CoreHeaders.ORIGINAL_URL);
request.headers.delete(CoreHeaders.DISABLE_PRETTY_ERROR);
return request;
}

Expand Down Expand Up @@ -208,11 +209,11 @@ export default <ExportedHandler<Env>>{
const isProxy = request.headers.get(CoreHeaders.OP) !== null;
if (isProxy) return handleProxy(request, env);

// `dispatchFetch()` will always inject the passed URL as a header. When
// `dispatchFetch()` will always inject this header. When
// calling this function, we never want to display the pretty-error page.
// Instead, we propagate the error and reject the returned `Promise`.
const isDispatchFetch =
request.headers.get(CoreHeaders.ORIGINAL_URL) !== null;
const disablePrettyErrorPage =
request.headers.get(CoreHeaders.DISABLE_PRETTY_ERROR) !== null;
RamIdeas marked this conversation as resolved.
Show resolved Hide resolved

request = getUserRequest(request, env);
const url = new URL(request.url);
Expand All @@ -227,7 +228,7 @@ export default <ExportedHandler<Env>>{
}

let response = await service.fetch(request);
if (!isDispatchFetch) {
if (!disablePrettyErrorPage) {
response = await maybePrettifyError(request, response, env);
}
response = maybeInjectLiveReload(response, env, ctx);
Expand Down