Created
August 27, 2012 17:26
-
-
Save mamund/3490606 to your computer and use it in GitHub Desktop.
XmlHttpRequest w/ compression support
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// typical generic request routine (handles GET and POST) | |
function makeRequest(href, next, body, contentType) { | |
var ajax; | |
ajax=new XMLHttpRequest(); | |
if(ajax) { | |
ajax.onreadystatechange = next(); | |
if(body) { | |
ajax.open('post',href,false); | |
ajax.setRequestHeaders('content-type',contentType); | |
ajax.setRequestHeaders('accept-encoding','gzip'); | |
ajax.send(body); | |
} | |
else { | |
ajax.open('get',href,false); | |
ajax.setRequestHeaders('accept-encoding','gzip'); | |
ajax.send(null); | |
} | |
} | |
} |
Using Content-Encoding: gzip
in the request headers does not work. Discussed here: http://stackoverflow.com/a/10346303/362271
Accept-Encoding
is one of forbidden header name.
See https://developer.mozilla.org/en-US/docs/Glossary/Forbidden_header_name
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks Mamund, but it should be:
Also, I get this error from Chrome: