如何在Response
对象上设置Content-Type
标头?
到目前为止我的代码:
new Response(
file[1],
{
status: 200,
// i have also tried "contentType", and "ContentType"
"Content-Type": "text/html",
},
)
在后台,我试图创建一个自定义的HTML文件,并将其和缓存API放在缓存中,默认为text/plain。
我在发布后就发现了:
new Response(
"response body here...",
{
status: 200,
headers: new Headers({
"content-type": "text/html;charset=UTF-8",
}),
},
)
您需要使用Headers构造函数并将其设置在";标题";键,然后可以设置所需的任何响应标头。