问题
I am working on a project where we need to add some custom headers to the HTTP requests for image, video and audio content in the browser. I've been looking around and not really coming up with a good answer, other than possibly creating browser plugins.
Decorating the URL is not an option at this time because the gateway is looking for headers.
I can get the content by AJAX requests and adding the header to AJAX requests, then reassembling the content, base64 encoding it, then feeding that to the image, video or audio element, using a data: URI for the src. but that is horribly inefficient, especially for videos, where we think the content may be as much as 120MB. This technique also does not allow the video element to buffer the stream.
So I am looking for ideas on how the native browser behavior can be used, but with injecting the required custom headers. Can I have
<img src="javascript:MyFunction(this)" />
or
<video src="javascript:MyFunction(this)" />
来源:https://stackoverflow.com/questions/31394120/add-custom-headers-to-img-video-and-audio-requests