开发者

Tokenising stream of HTTP messages in Objective-C

I have an NSData object that consists of several HTTP responses or requests concatenate开发者_如何转开发d together. What is the most effective way to tokenise this stream of requests/responses into individual CFHTTPMessageRef objects?

My current approach is to read the data one line at a time until CFHTTPMessageIsHeaderComplete returns YES, at which point I then grab the value of the Content-Length header to determine the length of the body associated with this particular request.

This approach works reasonably well, but fails in the case of chunked transfer encoding. I could now add additional logic to deal with chunked transfers, but my parsing logic will grow more than I would like. Similarly, I am only currently dealing with well-formed messages -- it will trip up should a message not be formatted perfectly.

Is there (ideally) a set of Objective-C classes that can parse a stream of data into discrete HTTP messages? Is this something that libcurl could perform?


No, libcurl cannot split up this for you. It only separates actual HTTP responses that it receives over the network.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜