Skip to content
This repository was archived by the owner on Mar 13, 2025. It is now read-only.

Commit 5310694

Browse files
authored
decouple MF-Original-URL header from disabling the pretty-error page (#689)
* decouple MF-ORIGINAL-URL header from disabling the pretty-error page now uses MF-Disable-Pretty-Error header explicitly * set DISABLE_PRETTY_ERROR value to "true" instead of ""
1 parent 431f005 commit 5310694

File tree

3 files changed

+7
-4
lines changed

3 files changed

+7
-4
lines changed

packages/miniflare/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1155,6 +1155,7 @@ export class Miniflare {
11551155
const forward = new Request(input, init);
11561156
const url = new URL(forward.url);
11571157
forward.headers.set(CoreHeaders.ORIGINAL_URL, url.toString());
1158+
forward.headers.set(CoreHeaders.DISABLE_PRETTY_ERROR, "true");
11581159
url.protocol = this.#runtimeEntryURL.protocol;
11591160
url.host = this.#runtimeEntryURL.host;
11601161
if (forward.cf) {

packages/miniflare/src/workers/core/constants.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
export const CoreHeaders = {
22
CUSTOM_SERVICE: "MF-Custom-Service",
33
ORIGINAL_URL: "MF-Original-URL",
4+
DISABLE_PRETTY_ERROR: "MF-Disable-Pretty-Error",
45
ERROR_STACK: "MF-Experimental-Error-Stack",
56
ROUTE_OVERRIDE: "MF-Route-Override",
67

packages/miniflare/src/workers/core/entry.worker.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ function getUserRequest(
5757
request = new Request(request, { cf: env[CoreBindings.JSON_CF_BLOB] });
5858
}
5959
request.headers.delete(CoreHeaders.ORIGINAL_URL);
60+
request.headers.delete(CoreHeaders.DISABLE_PRETTY_ERROR);
6061
return request;
6162
}
6263

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

211-
// `dispatchFetch()` will always inject the passed URL as a header. When
212+
// `dispatchFetch()` will always inject this header. When
212213
// calling this function, we never want to display the pretty-error page.
213214
// Instead, we propagate the error and reject the returned `Promise`.
214-
const isDispatchFetch =
215-
request.headers.get(CoreHeaders.ORIGINAL_URL) !== null;
215+
const disablePrettyErrorPage =
216+
request.headers.get(CoreHeaders.DISABLE_PRETTY_ERROR) !== null;
216217

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

229230
let response = await service.fetch(request);
230-
if (!isDispatchFetch) {
231+
if (!disablePrettyErrorPage) {
231232
response = await maybePrettifyError(request, response, env);
232233
}
233234
response = maybeInjectLiveReload(response, env, ctx);

0 commit comments

Comments
 (0)