HTTP頭控制
更新時間 2023-12-04 20:31:30
最近更新時間: 2023-12-04 20:31:30
分享文章
本文介紹如何使用邊緣函數更改在請求中發送或在響應中返回的標頭。
更改在請求中發送或在響應中返回的標頭。
示例代碼
addEventListener('fetch', event => {
event.respondWith(handleRequest(event.request))
})
async function handleRequest(request) {
const response = await fetch(request)
// 添加新的頭
response.headers.append("X-Hello", "hello from ctyun")
// 修改舊的頭
response.headers.set("Etag" ,"4kf36KRuEB")
return response
}
示例預覽
相關HTTP頭被修改。
