
Phil Endecott wrote:
Hi Peter,
Peter Petrov wrote:
Let me chime in, as I've recently developed an Asio-based HTTP server as well.
First, Spirit is unsuitable for the task - it consumes all the input in one pass, and doesn't support the case when the HTTP request arrives in more than one read. The real solution is a state-machine-based parser, just like the one in the Asio HTTP example.
I disagree in general. My parser is primarily an HTTP request _header_ parser, and the headers are normally relatively small. For most requests (i.e. GETs) the request body doesn't add much, and in those cases it is likely that the whole request can be got in a single read. In fact browser implementations go to some lengths to make their requests fit in single network packets (about 1500 bytes) for performance reasons, and single network packets will generally be accessible as single reads.
I normally use this code in a thread-per-connection environment, but if you wanted to use it in a single-threaded system you would need to modify it to detect incomplete input in the (rare) case when the input was split over multiple packets.
In the case of HTTP POST and PUT requests, on the other hand, the body (but not the header) can be large, and parsing it incrementally as it arrives probably is necessary. I noticed a BoostCon paper about a MIME parser (Marshall?) - this would definitely benefit from working incrementally in many applications.
While not wanting to be self-serving .... I will be discussing how to use Spirit and Asio together at BoostCon in presentations on Spirit and Asio. I have been developing a utility that works well for many of my applications that require asynchronous messaging. I have also utilized it with embedded HTTP servers. While the source works well and is shipping with a few client projects, it is rough in Boost terms and is going through refinements for a May introduction. I tend to agree with Phil. My experience is that provided the correct model, Spirit (both Qi and Karma) work perfectly fine in this domain. Best Regards - michael -- ---------------------------------- Michael Caisse Object Modeling Designs www.objectmodelingdesigns.com