The Browser Extensions Standard (which is based on the Chrome Extension API) includes a webRequest
API with methods onBeforeSendHeaders
and onHeadersReceived
, allowing a browser extension to see and modify HTTP headers in requests and responses.
The HTTP headers are provided as an array of objects. Each object has a name
(e.g. 'content-type'
) and then it has either a value
(e.g. 'text/html'
) or a binaryValue
(represented as an array of integers). According to MDN you get a binaryValue
only if the value "cannot be represented by UTF-8". But how can that actually happen? Under what circumstances can there exist an HTTP header whose value is not representable as a UTF-8 string?
I can't find a single example in the wild, or even any mention online, of binary HTTP header values. For example, in Node's built-in http2 module, the response.setHeader(name, value)
method only accepts a string (or an array of strings) for the value
.