I have a programming project where I have to create a multithreaded web server which handles HTTP requests.
I just learned socket programming and I got a client and a server running. I wanted to know what the best method would be for parsing the HTTP request headers. I saw this: how to parse http request in c++ a few minutes back. But I would rather not shift to C++ at this point. So how should one go about parsing an HTTP request in C?
You can have a look at the web servers in C such as mongoose (https://github.com/cesanta/mongoose/blob/master/mongoose.c) and could use the same methodology to parse the http request. But what would I suggest is that just go through the HTTP RFC 2616 since that would help you in writing your own parser for http requests.
By the way which kind of HTTP requests your Server is handling (GET or POST or BOTH) ??
In http post requests the HTTP header & data are separated by "\r\n\r\n".
In received data sscanf the Content-Length form the http header then start reading the data after you get "\r\n\r\n" until you get the same amount of data as mentioned in Content-Length.