Closed Bug 455850 Opened 16 years ago Closed 16 years ago

XMLHttpRequest ignores encoding part of header "Content-Type" and overrides it to UTF-8

Categories

(Core :: DOM: Core & HTML, defect)

x86
Windows XP
defect
Not set
major

Tracking

()

RESOLVED DUPLICATE of bug 416178

People

(Reporter: BoD, Unassigned)

Details

User-Agent:       Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.0.1) Gecko/2008070208 Firefox/3.0.1 (.NET CLR 3.5.30729)
Build Identifier: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.0.1) Gecko/2008070208 Firefox/3.0.1 (.NET CLR 3.5.30729)

Given this little JavaScript example:

var request = new XMLHttpRequest();
var url = "someurl";
request.open("POST", url, true);
request.setRequestHeader( "Content-Type", "application/x-www-form-urlencoded; charset=ISO-8859-1");
request.send("test");

In Firefox 2 (in Internet Explorer 7 too), the header is correctly sent:
Content-Type: application/x-www-form-urlencoded; charset=ISO-8859-1

In Firefox 3, here is the header that is actually sent:
Content-Type: application/x-www-form-urlencoded; charset=UTF-8

Notice how the charset has been overriden!

Reproducible: Always

Steps to Reproduce:
1.Copy/paste the example above
2.Run it
3.Use firebug or a network analyser to see the actual headers
Actual Results:  
The "charset" part of the Content-Type header is always UTF-8.

Expected Results:  
The "charset" part of the Content-Type header is whatever was specified when calling setRequestHeader.

Server-side applications expecting ISO-8859-1 are broken because of this behaviour. Marking the severity as major because of this.
Version: unspecified → 3.0 Branch
Component: General → DOM: Mozilla Extensions
Product: Firefox → Core
QA Contact: general → general
Version: 3.0 Branch → Trunk
I want to confirm this bug.  It is causing problems with our server recognizing form variables in a POST.

It also occurs using Firefox3 on Macintosh. 
 
If a value is explicitly set using JavaScript using setRequestHeader(), it should be literally passed to the server and not be changed in any way.

I should be able to set Content-Type to "xyz" if there is some reason my server needs to know that.
Mozilla encodes the string you pass to send() as UTF-8. If you start passing in non-ASCII parameters this will make a difference, and sending ISO-8859-1 would be wrong.
Does this mean you confirm this behavior, and it's not a bug but a wanted feature?
Probably INVALID, see http://www.w3.org/TR/XMLHttpRequest/#send, for data is a DOMString: "If a Content-Type header is set using setRequestHeader() set the charset parameter of that header to UTF-8.".
(In reply to comment #3)
> Does this mean you confirm this behavior, and it's not a bug but a wanted
> feature?

yes.
Status: UNCONFIRMED → RESOLVED
Closed: 16 years ago
Resolution: --- → DUPLICATE
There is an alternate method to use sendAsBinary() instead of send() and the Content-Type set using setRequestHeader() is not changed by Firefox3.  This fixed the problem I was having with my server.  see http://developer.mozilla.org/en/XMLHttpRequest
Component: DOM: Mozilla Extensions → DOM
Component: DOM → DOM: Core & HTML
You need to log in before you can comment on or make changes to this bug.