I’ve got a weird & frustrating problem fetching an HTTP resource with NSURLConnection, and my current hypothesis is that it’s something to do with the way CFNetwork handles chunked responses; specifically, that it waits until the complete response is available before calling any of the delegate methods. Is that so?
Here are the specifics: I’m reading a CouchDB _changes feed [1] in ‘continuous’ (aka streaming) mode, where the server never ends the response, but keeps sending data continuously as it becomes available. I’ve been using NSURLConnection for years for all kinds of things, but this time I’m stumped, as I can’t get it to work at all on this feed.
What I see is that I create the connection (ignoring local & remote caches), and then none of the delegate methods ever get called, no matter how long I wait. I know the code is basically correct because if I change the URL slightly to specify the non-streaming mode (in which it sends one chunk of data and ends the response), the delegate calls happen as normal and my code works.
The problematic URL works fine when accessed through ‘curl’. But it also fails with the ‘HTTP Client’ app, which presumably also uses NSURLConnection.
My current hypothesis, as I said, is that when CFNetwork receives an HTTP header with “Transfer-Encoding: chunked”, it doesn’t call the delegate as usual, but instead waits until it’s received the entire response body before unchunking it and sending it to the delegate in one lump.
Is that so? If true, I’m going to have to reluctantly abandon NSURLConnection and fetch this resource using a plain NSStream. :(
|