addEventListener('fetch', event => {
event.passThroughOnException();
event.respondWith(handleRequest(event.request));
});
async function handleRequest(request) {
const url = new URL(request.url);
const fileName = url.searchParams.get('fileName');
const response = await fetch(request);
if (response.status !== 200 || !fileName) {
return response;
}
response.headers.append('Content-Disposition', `attachment; filename="${fileName}"`);
return response;
}
示例预览
在 PC 端与移动端的浏览器地址栏中输入匹配到边缘函数触发规则的 URL(如:https://example.com/origin.exe?fileName=modified.exe
),即可预览到示例效果。
相关参考
本页内容是否解决了您的问题?