Boost logo

Boost :

Subject: Re: [boost] C++ Networking Library Release 0.5
From: Peter Petrov (ppetrov_at_[hidden])
Date: 2010-02-01 14:56:31


On Mon, Feb 1, 2010 at 1:26 PM, Glyn Matthews <glyn.matthews_at_[hidden]>wrote:

> On 31 January 2010 12:08, Phil Endecott <spam_from_boost_dev_at_[hidden]
> >wrote:
> > James Mansion wrote:
> >> Phil Endecott wrote:
> >>> I have an HTTP request parser using Spirit, if you're interested. It
> is
> >>> a bit grotty as I wrote it as my first exercise using Spirit - but it
> does
> >>> work. http://svn.chezphil.org/libpbe/trunk/src/parse_http_request.cc.
> >>>
> >> Out of interest, is the parser suitable to use as a tutorial on how to
> >> translate from RFC specs?
> >>
> >
> > You're welcome to use it in that way if you wish. Most of it was
> translated
> > directly from the BNF in the RFCs.
> >
>
> I would say that this is on-topic as it is an issue that we face in
> implementing cpp-netlib. Currently, the request parser in the HTTP server
> is taken from Boost.Asio HTTP example but I'm certain that this can be
> improved.
>
>

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.

In my case, I used an automatically generated parser from EBNF, via Ragel (
http://www.complang.org/ragel/). The grammar itself I "borrowed" from the
sandbox version of Lighttpd, which uses the same approach. Link:

http://redmine.lighttpd.net/projects/lighttpd-sandbox/repository/revisions/master/entry/src/main/http_request_parser.rl

Ragel is the best solution I'm aware of, and it's easy to integrate its
output into Boost-style C++ code. I've not yet benchmarked my solution
against the Asio HTTP example parser for performance, but I assume they are
close.

Regards,
Peter


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk