Skip to content

Commit

Permalink
worker: Fetch the upstream status code from x-original-status-code
Browse files Browse the repository at this point in the history
For supporting worker sites we hardcoded the status code to 200 since we
don't have access to the status code of the original request. This
allows to forward a custom status code via `x-original-status-code`
header.

Relates to #27.

Signed-off-by: Jorge Luis Betancourt Gonzalez <[email protected]>
  • Loading branch information
jorgelbg committed Feb 15, 2021
1 parent 74e1bd2 commit 0083d06
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,10 @@ async function handleRequest(event: FetchEvent): Promise<Response> {
// to the worker and that therefor the upstream should not be fetched. We use a custom header to
// change as little as possible from the original request.
if (request.headers.get('x-original-url') != null) {
response = new Response('ok', { status: 200 })
let statusCode: number = parseInt(
request.headers.get('x-original-status-code') || '200',
)
response = new Response('ok', { status: statusCode })
} else {
// fetch the original request
console.log(`Fetching origin ${request.url}`)
Expand Down

0 comments on commit 0083d06

Please sign in to comment.