Build a simple HTTP server in C
I suggest you take a look at tiny httpd. If you want to write it from scratch, then you'll want to thoroughly read RFC 2616. Use BSD sockets to access the network at a really low level.
I'd recommend that you take a look at: A Practical Guide to Writing Clients and Servers
What you have to implement in incremental steps is:
- Get your basic TCP sockets layer running (listen on port/ports, accept client connections and send/receive data).
- Implement a buffered reader so that you can read requests one line (delimited by CRLF) at a time.
- Read the very first line. Parse out the method, the request version and the path.
- Implement header parsing for the "Header: value" syntax. Don't forget unfolding folded headers.
- Check the request method, content type and content size to determine how/if the body will be read.
- Implement decoding of content based on content type.
- If you're going to support HTTP 1.1, implement things like "100 Continue", keep-alive, chunked transfer.
- Add robustness/security measures like detecting incomplete requests, limiting max number of clients etc.
- Shrink wrap your code and open-source it :)