Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to remove HTTP specific headers in Javascript

Is it possible to, before sending a http message, remove some specific http headers using javascript / XmlHttpRequest ?

I'm using a proprietary browser, so there's no way to do it using browser specific solution.

For example, I want to remove the header 'Authorization' before send the message

POST /social/rpc?oauth_version=1.0& ... HTTP/1.1

Accept: text/html, image/png, image/*, */*
Accept-Language: ko
Authorization: Basic Og==
Host: test.myhost.com

Regards

like image 414
Andres Avatar asked Mar 17 '10 16:03

Andres


People also ask

How to remove a header in Javascript?

delete() The delete() method of the Headers interface deletes a header from the current Headers object.

How do I remove HTTP request header?

The dp:remove-http-request-header function removes a specific header field and its associated value from the protocol header of a client request. If the client request contains the header field that is identified by the name parameter, the function removes this header field from the client request.

How do I remove a header from a website?

Click Page Setup. Click the Margins & Headers/Footers tab. Change the top three and bottom three drop-down menus to "--blank--" if you want to remove all the headers and footers.


2 Answers

You could use the setRequestHeader method of the XmlHttpRequest object assuming your browser supports it, It is part of the W3C spec. It is also implemented by IE.

var req = new XMLHttpRequest();
req.setRequestHeader("Authorization", "");
like image 105
Adam Avatar answered Oct 04 '22 01:10

Adam


When I use jquery-file-upload, and want to remove the header in the options method, setting it to null or '' doesn't work for me. I use this instead:

req.setRequestHeader("Authorization");

like image 42
Fancyoung Avatar answered Oct 04 '22 02:10

Fancyoung