xhr.setHeader('Content-type', 'application/json') fails to set Content-type header.
Reported by Yesudeep Mangalapilly | July 27th, 2009 @ 10:57 AM
Here's the offending piece of code:
var xhr = new Xhr('/api', {
onSuccess: function(){
console.log('success!');
}
});
xhr = xhr.setHeader('Content-type', 'application/json');
xhr.send(JSON.stringify({
"version": "1.1",
"method": "get_users",
"id": 1,
"params": []
}
));
Here's the HTTP header information.
http://localhost:8000/api
POST /api HTTP/1.1
Host: localhost:8000
User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.1.2pre) Gecko/20090726 Ubuntu/9.04 (jaunty) Shiretoko/3.5.2pre
Accept: text/javascript, text/html, application/xml, text/xml, */*
Accept-Language: en-us,en;q=0.5
Accept-Encoding: gzip,deflate
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
Keep-Alive: 300
Connection: keep-alive
X-Requested-With: XMLHttpRequest
Content-Type: application/x-www-form-urlencoded; charset=utf-8
Referer: http://localhost:8000/admin
Content-Length: 57
Cookie: blackbird={pos:1,size:1,load:null}; dev_appserver_login="test@example.com:True:185804764220139124118"; appengine-utilities-session-sid=agttaWxzLXNlY3VyZXIhCxIbX0FwcEVuZ2luZVV0aWxpdGllc19TZXNzaW9uGAcM7fd8170b1961769ab6d2b13b459e9292
Pragma: no-cache
Cache-Control: no-cache
{"version":"1.1","method":"get_users","id":1,"params":[]}
HTTP/1.x 200 OK
Server: Development/1.0
Date: Mon, 27 Jul 2009 06:52:25 GMT
Cache-Control: no-cache
Pragma: no-cache
Content-Type: application/json
Content-Length: 2374
Comments and changes to this ticket
-
MadRabbit July 27th, 2009 @ 11:08 AM
Hi Yesudeep,
There's a default option called 'urlEncoded', which is true by default
and it forces the formencoded content type. You could avoid the thing
by doing the things like thatnew Xhr('/api', {
urlEncoded: false, onSuccess: function() {// log it here
}; }) .setHeader('Content-type', 'application/json') .send(....);
But I see your point and think it a good idea if it would keep the
user defined content-type. will fix it. -
Yesudeep Mangalapilly July 27th, 2009 @ 04:17 PM
Oh, nice. I can probably use that suggestion to go right ahead.
However, yes, I second that it would be good to keep the user
defined content-type.Thanks. :-)
-
MadRabbit July 28th, 2009 @ 12:31 PM
- State changed from new to resolved
I've updated the build on the server. Now it includes a patch for your case
Please let me know how is it going with you using RightJS
Please Sign in or create a free account to add a new ticket.
With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.
Create your profile
Help contribute to this project by taking a few moments to create your personal profile. Create your profile ยป
RightJS Core Tickets