I have a plugin that blocks NSFW images using WebRequest. Currently, it scans the image and then either returns the original image or creates an SVG with more details in it and the original image. In order to get that to work, I currently modify the content-type for all images I can to be image/svg+xml. Now, this likely works because of MIME type sniffing, rather than being strictly correct - unmodified images shouldn’t have their MIME types changed.
However, in the case that I directly load an image (e.g. “main_frame” in WebRequest types), if I pass through say JPEG bytes when I have already restamped the MIME type as image/svg+xml, I get an SVG XML document parsing error.
So suppose I try deferring to change the MIME type until after I’ve scanned the image in WebRequest.StreamFilter.onstop (but before I call filter.write). When I try it, it doesn’t seem to pick up the changed MIME type.
To me this makes good sense - the headers have already likely been consumed downstream and it likely matches the workflow shown here: https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/API/webRequest
However, have I perhaps missed something? Is there a way to change the MIME type after the whole data block has been received when using WebRequest in a blocking scenario?