Add custom headers to IMG, VIDEO and AUDIO requests

眉间皱痕 提交于 2020-01-12 18:46:10

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!