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';
    dojo.io.bind({
        url: "http://example.com/my/api/call/,
        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') {
                $this->_redirect('/my/other/page');
       }

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') {
                $this->_redirect('/my/other/page');
       }

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,
(l)(k)(bunny)
=C=

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.

No tag for this post.

Related posts