|401's, why have you forsaken me? (adventures in #webOS)
||[Aug. 28th, 2011|12:33 pm]
TL;DR - 401 errors are important! Handle them correctly!
I've started work on porting LJ for WebOS (LiveJournal client) to Enyo and the TouchPad...and it is not going well.
This is all a bit clumsy, but worked great in the existing LJ for WebOS. Last night I got to the point where I was actually trying to get posts in the new version. First up was developing in Chrome - one of the nicest part of the new webOS framework is that it's easy to test most things in Chrome instead of having to fire up the emulator and install it, etc. I noticed that when I tried this code for the first time, I got a bunch of popups in the browser asking for a username and password for various LJ sites. If I hit Cancel on all of them, things seemed to work - the code then saw the 401 error and proceeded to authenticate normally.
This seemed odd, to say the least, so I did a quick search which led me to this StackOverflow page (yay StackOverflow!), which says that's it's a known issue in Chrome and the only way to work around it doesn't work in my case (because I need to know what the headers on the 401 error are).
Well, that's pretty annoying, and seems clearly wrong to me - the user didn't go to this page, so why is she being asked for a username/password? I could see that you might want the option to do this in some cases, but the default should be off.
So I was already a bit irritated and, after a little bit more work, decided to try it in the webOS TouchPad emulator. I watched the logs scroll by as it got to the point that it did the first request for the post pages and then...nothing. Only when I quit the app by throwing the card away did I get some not-really-sensical error indications in the log.
I rebooted the emulator (as it seems to have a problem once you do too many HTTP requests or something), and the same thing happened. I was a bit at a loss - since I wasn't getting any of my log messages I couldn't see at all what was going on. Finally I fired up Wireshark to see the HTTP requests that the emulator was making to see if there was a clue there.
Much to my surprise, I saw it requesting the same pages over and over again! It would do a request, get back a 401 Unauthorized response, and then do a request again, seemingly trying to authenticate with an empty username and who knows what password.
I looked through my code and tried a few things to make sure that I wasn't causing this, but after some more searching I found a private thread confirming this behavior and that it was a bug.
*sigh* I can't make any more progress while this bug exists, and who knows when (or if?) it will be fixed in the OS. So, if anyone asks, this is why LJ for WebOS isn't on the TouchPad, and I guess I'll move on to other projects for now...
(this probably also mean that running the phone-sized version on the TouchPad won't work either, so...sorry about that. I don't have the heart to try it out right now.)