Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set custom header for the request made from <img/> tag

Let's say I have a code like this:

<img src='images/whatever.jpj' width='' height=''/> 

How to configure custom headers for this request?

Will appreciate any help.

like image 825
andrey Avatar asked Nov 18 '14 17:11

andrey


People also ask

Can I add custom header to HTTP request?

In the Home pane, double-click HTTP Response Headers. In the HTTP Response Headers pane, click Add... in the Actions pane. In the Add Custom HTTP Response Header dialog box, set the name and value for your custom header, and then click OK.

What is HTTP request custom header?

Custom HTTP headers are commonly meant to provide additional information that may be pertinent to a web developer, or for troubleshooting purposes. These headers often times begin with X- , however, we'll discuss naming convention further on.


1 Answers

I'm late here, but you can do this with XMLHttpRequest and a blob.

var xhr = new XMLHttpRequest(); xhr.responseType = 'blob'; //so you can access the response like a normal URL xhr.onreadystatechange = function () {     if (xhr.readyState == XMLHttpRequest.DONE && xhr.status == 200) {         var img = document.createElement('img');         img.src = URL.createObjectURL(xhr.response); //create <img> with src set to the blob         document.body.appendChild(img);     } }; xhr.open('GET', 'http://images.example.com/my_secure_image.png', true); xhr.setRequestHeader('SecretPassword', 'password123'); xhr.send(); 

If you want, you could check to make sure the blob's MIME type is an image.

like image 50
robbie Avatar answered Sep 20 '22 02:09

robbie