views:

35

answers:

0

Why won't IE let me see the get the Content-Length header with getResponseHeader()?

I know there the headers are being sent; I can see them with Wireshark. IE just won't let me get them.

If the Content-Encoding header is NOT sent, regardless of if the content-is gzipped or not, I can get them just fine.

Sample Code:

    function getXMLHttpRequest() {
        if (window.XMLHttpRequest) {
            return new window.XMLHttpRequest;
        }
        else {
            try {
                return new ActiveXObject("MSXML2.XMLHTTP.3.0");
            }
            catch (ex) {
                return null;
            }
        }
    }
    function handler() {
        if (oReq.readyState == 4 /* complete */) {
            if (oReq.status == 200) {
                // this alert will be missing Content-Length 
                // and Content-Encoding if Content-Encoding is sent.
                alert(oReq.getAllResponseHeaders());
            }
        }
    }

    var oReq = getXMLHttpRequest();

    if (oReq != null) {
        oReq.open("GET", "http://www.example.com/gzipped/content.js", true);
        oReq.onreadystatechange = handler;
        oReq.send();
    }
    else {
        window.alert("AJAX (XMLHTTP) not supported.");
    }