Postcards From My Life

Lint I find in my mind's belly-button.
  • EPK
  • Consulting
  • Resume
  • Nerd Herding
  • Talks
  • How to Plan a Website
  • Zend Framework
« Uber PHP Conference
Tales from the Dog House »

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';
    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.

Buffer

This entry was posted on Tuesday, January 2nd, 2007 at 10:23 pm and is filed under JavaScript, PHP, Programming. You can follow any responses to this entry through the RSS 2.0 feed. Both comments and pings are currently closed.

Logging In...

Comments are closed.

  • 1 Reply
  • 1 Comment
  • 0 Tweets
  • 0 Facebook
  • 0 Pingbacks
Last reply was January 14, 2008
  1. Alexandre Magno
    View January 14, 2008

    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…

  • Friends of mine

  • My Latest Book


    Avoiding a Goat Rodeo

  • Follow me on twitter!

  • RSS PHP Podcasts

    • Episode 33: Pol Pot-level Sucks
    • Episode 32: tek13
    • Episode 110: Azure hits 1 billion, RubyFlux compiler, Laracasts and more
    • Episode 7: Web Sockets Are Fast
    • Better Documentation for PHP internals – Lately in PHP podcast episode 35
    • Episode 32: tek13
    • Episode 31: Feline Tooth Extraction
    • Episode #2 – Adam Culp
    • Episode 6: PSR-X and the Mexican Standoff
    • Episode 109: Typescript and a bit more…

  • Me, elsewhere on the Web

    • Best web design company
    • Cal Evans Dot Com
    • Cyrano’s Apprentice
    • Evans Internet Construction Company
    • My Life as a Child
    • PHP Podcasts

  • Categories

    • Apache
    • BlogBling
    • Blogging
    • Book Review
    • codeworks
    • Entertainment
    • Entrepreneurship
    • Flex
    • Humor
    • JavaScript
    • Long Form
    • Management
    • Marketing
    • Me, elsewhere on the Web
    • PHP
    • podcasting
    • Programming
    • SQL
    • Technology
    • Web 2.0
    • wordpress
    • WordPress Plugins
    • writing
    • zend framework


Postcards From My Life is proudly powered by WordPress
Entries (RSS) and Comments (RSS).