[cs631apue] HTTP Request Parsing

Jan Schaumann jschauma at stevens.edu
Sun Dec 11 09:50:30 EST 2011


Peter Okma <pokma at stevens.edu> wrote:
> How many assumptions can we make about the format of incoming HTTP
> requests?

You can assume that the request lines do not wrap and that individual
components are whitespace separated.  Since you only support one
client request header, you you can ignore all others and do not need to
care about their formatting either.  That is, the following requests are
valid for your server:

GET / HTTP/1.0\n\n

GET    /    HTTP/0.9\n\n

HEAD /something     HTTP/1.0\n\n

GET /file HTTP/1.0\nIf-Modified-Since: Sat, 29 Oct 1994 19:43:31 GMT\n\n

GET /whatever HTTP/1.0\nIgnore-This: something\nIgnore-That: something\nIf-Modified-Since: Sun, 11 Dec 2011 09:44:11 EST\n\n

GET /whatever HTTP/1.0\nIgnore-This: something\nIf-Modified-Since:              Sun, 11 Dec 2011 09:44:11 EST\nIfnote-That\n\n


You do not need to worry about additional whitespace between the
elements in the request (say, between "HTTP" and "/" and "1." and "0").

Also, being able to parse even the most obscure but rfc-compliant
request isn't the most important aspect of the assignment.  It's good
that you think about this, though.

> Would we be able to use a third party code such as,
> https://github.com/joyent/http-parser, if  properly attributed?

No, this project is to be done without the help of third-party
libraries.

> If not could you recommend a general approach to parsing that would be
> robust enough for this projects requirements.

Focus on suitable request detection, for example by splitting elements
by (any number of) whitespace and don't worry about line continuation.

-Jan


More information about the cs631apue mailing list