iOS6 HTTP POST Blunder

Posted on Updated on

It usually is quite amazing when someone upgrades their iPhone to a new OS and suddenly things stop working. By "things" I mean web-applications and by "not working" I mean they literally stop working.

This affected me and my work. Suddenly people who visit one of my web-applications cannot use it properly. They seemed to only be able to send HTTP POSTs but not receive. Weird, then we see the issue completely exploded on stackoverflow which is a good thing because it means it’s not you that fu**ed up this time 🙂 it’s an SEP.

Apple in their great and infinite wisdom have decided to make Safari on iOS6 cache HTTP Post requests unless explicitly specified in the header not to cache it. Which does not make a lot of sense. Mark Nottingham who chairs the IETF HTTPbis Working Group analyzed the statements of the HTTP spec (RFC 2616) and showed there is vagueness or as my old university professor used to always say about 30 times a day "ambiguity". You can read his post here where he goes into detail on the very wording of the RFC and how it applies, or you can read his conclusion below:

So, POST caching is possible, but it’s only useful in a very narrow way — when you want to use the result of the POST to serve future GETs for the same URI. And, as the spec says, it’s not commonly implemented. See Subbu’s example and links to discussion at the time for more information.

Back to Apple: even without the benefit of this context, they’re still clearly violating the spec; the original permission to cache in 2616 was contingent upon there being explicit freshness information (basically, Expires or Cache-Control: max-age).

So, it’s a bug. Unfortunately, it’s one that will make people trust caches even less, which is bad for the Web. Hopefully, they’ll do a quick fix before developers feel they need to work around this for the next five years.

Further to this he has made a modification to the spec to make it clearer so the geniuses at Apple do not end up making things not work after an upgrade.

Many people started offering up suggestions and workarounds to which I found this blog (by devthought) to document the best of it. They also talk about the other bugs that came with iOS6 concerning safari.

For me this simple workaround worked best. Add a clause in Apache’s http config to automatically add a header not to cache for all POST requests

<IfModule mod_setenvif.c>
        SetEnvIf Request_Method "POST" IS_POST
        Header add Pragma "no-cache" env=IS_POST

Leave a Comment

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s