Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to change response header in Chrome

I'm dealing with some mp3 link on the internet.

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).

Are there any Chrome extensions that allow changing response header? Because I want to change Content-Type

like image 389
onmyway133 Avatar asked Dec 04 '12 10:12

onmyway133


People also ask

Can we set response header?

You can set response headers, you can add response headers. And you can wonder what the difference is. But think about it for a second, then do this exercise. Draw a line from the HttpResponse method to the method's behavior.


1 Answers

See the Chrome developer page.

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']);

Note that you have to declare both webRequest and webRequestBlocking permissions in manifest.json.

like image 177
方 觉 Avatar answered Oct 08 '22 13:10

方 觉