如何在 Chrome 中更改响应标头 [英] how to change response header in Chrome
问题描述
我正在处理互联网上的一些 mp3 链接.
I'm dealing with some mp3 link on the internet.
当使用 Chrome 开发者工具时,我看到一些响应头带有 Content-Type:application/octet-stream
(像这样的链接强制 Chrome 下载),一些链接带有响应头 Content-Type:audio/mpeg
(这样的链接允许 Chrome 流式播放它们).
When using Chrome developer tool, I see some have response header with Content-Type:application/octet-stream
(links like these force Chrome to download), some links have reponse header with Content-Type:audio/mpeg
(links like these allow Chrome to play them streamingly).
是否有任何允许更改响应标头的 Chrome 扩展程序?因为我想改变Content-Type
Are there any Chrome extensions that allow changing response header? Because I want to change Content-Type
推荐答案
查看Chrome 开发者页面.
这是一个简单的例子,将 https://www.google.com/
的 Content-Type
修改为 text/plain.
Here's a simple example that modifies Content-Type
of https://www.google.com/
to text/plain.
chrome.webRequest.onHeadersReceived.addListener(details => {
let header = details.responseHeaders.find(e => e.name.toLowerCase() === 'content-type') ;
header.value = 'text/plain';
return {responseHeaders: details.responseHeaders};
}, {urls: ['https://www.google.com/']}, ['blocking', 'responseHeaders']);
请注意,您必须在 manifest.json
中同时声明 webRequest
和 webRequestBlocking
权限.
Note that you have to declare both webRequest
and webRequestBlocking
permissions in manifest.json
.
这篇关于如何在 Chrome 中更改响应标头的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!