fix(cf-worker): properly set Headers

This commit is contained in:
Ming Di Leom 2024-10-06 21:18:56 +00:00
parent 0b55a37381
commit fd4c2043a6
No known key found for this signature in database
GPG Key ID: 32D3E28E96A695E8
2 changed files with 4 additions and 8 deletions

View File

@ -101,10 +101,8 @@ export default {
const { readable, writable } = new TransformStream()
const { status, statusText } = response
const htmlHeader = new Headers({
...Object.fromEntries(request.headers),
Accept: 'text/html'
})
const htmlHeader = new Headers(request.headers)
if (!/text\/html/.test(accept)) htmlHeader.append('Accept', 'text/html')
const page404 = new Request('https://mdleom.com/404', {
headers: htmlHeader
})

View File

@ -1,10 +1,8 @@
export async function onRequestGet (context) {
const { pathname } = new URL(context.request.url)
const imageURL = new URL(pathname, 'https://mdleom.com')
const headers = new Headers({
...Object.fromEntries(context.request.headers),
'Host': 'mdleom.com'
})
const headers = new Headers(context.request.headers)
headers.set('Host', 'mdleom.com')
const imageRequest = new Request(imageURL, {
headers
})