Using CFHTTPMessage to parse response header but not body?
Using CFHTTPMessage to parse response header but not body?
- Subject: Using CFHTTPMessage to parse response header but not body?
- From: Jens Alfke <email@hidden>
- Date: Mon, 14 May 2012 10:30:27 -0700
Context: I’m receiving an HTTP response over a CFStream. I am using the plain CFStream API, not CFReadStreamCreateForHTTPRequest, so I have to do the parsing of the response myself. (This is all to work around a bug in CFNetwork’s HTTP parsing.)
It would be nice to have CFHTTPMessage do the parsing of the response line and headers for me. I can create an empty instance, then call CFHTTPMessageAppendBytes on it as data arrives. The problem is, I need to parse the body of the response myself, so I only want the CFHTTPMessage to consume the bytes up to the trailing two CRLFs after the headers.
But I can’t see a way to make it do that. Reading between the lines of the API, it seems to want to read the response body as well as the headers, and it won’t tell me where the headers end. For instance, if I pass it data that contains the last part of the headers and then some bytes of the body, it will eat all the bytes, then return true from CFHTTPMessageIsHeaderComplete … but I then don’t know how many bytes it consumed were headers and how many were body, so I’ve lost the beginning of the body.
Or am I missing something?
I can work around this by pre-scanning the response data and looking for the two CRLFs, then only passing CFHTTPMessage the data up to that point. But that seems kludgy, since after all the reason I’m doing this is so that I _don’t_ have to know about the formatting of the headers.
—Jens
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Macnetworkprog mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden