Skip to content

Internet Explorer XHTTP munges custom headers.

Dear Reader,

Elvis H. Presley! why does Microsoft have to make up their own rules for everything? Why, just for once, can’t they play nice and do things the way everybody else does? Nope, they’ve got to do things just enough different so that I have to make work-arounds.

Ok, here’s the scenario I hit upon tonight and banged head against for about 5 minutes till I saw what was happening.

Using DoJo as my Ajax transport I have the following code in a project.

    sendHeaders = new Object();
    sendHeaders['X-Return-Type'] = 'JSON';{
        url: ",
        load: displayData,
        headers: sendHeaders

Notice that I set a header “X-Return-Type”. See how nice I was to capitalize the words? That’s because I like them that way. (No major technical reason, I’ll admit, I just like it that way.)

Ok, now, in PHP:

        $headers   = apache_request_headers();
        if (!isset($headers['X-Return-Type']) or
            $headers['X-Return-Type']!='JSON') {

Ok, pretty straight forward, I set a header and I check for it. The problem is that in IE it’s failing. but why? If you check the headers being sent you’ll find that IE is nice enough to lowercase the header before sending it. This invalidates my isset() test.

So, the answer I came up with (I’m sure there are others) is:

        $headers   = array_change_key_case(apache_request_headers(),CASE_LOWER);
        if (!isset($headers['x-return-type']) or
            $headers['x-return-type']!='JSON') {

Convert all the keys to lowercase before testing. Ok so it works but c’mon guys, this is just petty. It looks to me like the MS XHTTP object is lowercasing this header before sending it out.

Thank you IE development team for taking the time to break the standards just enough to make me have to waste time tracking something down.

Arrrrgh! I’m going to bed!

Until next time,

p.s. No, I’ve not tested this in IE 7, I’m trying to avoid loading that steaming pile on my computer. If someone does test, I’d appreciate a comment.

DISCLAIMER: The opinions I express here are mine and mine alone. Go get your own.

One thought on “Internet Explorer XHTTP munges custom headers.

  1. Hi mate,

    I was defeating the same problem and the same headache, I really appreciate your help, very thanks.

    Im defeating a lot of trouble with ie, it really sucks. My hope is the ie 8, but its my fear too, because the ie 7 dont help at all…

    The people use this browser because came with os, so even with a lot of facilities of firefox install, theres a trouble with that…

    one more time, very thanks…

Comments are closed.