Sure you could write one yourself. The HTTP protocol is vast but you don't have to be a fully compliant web server to run your own application.
The C application would have to listen to requests on whatever port you decide to run the server at (default 80). There are various request methods in HTTP, but at a minimum you would have to implement GET
, or maybe even POST
but that aspect you can control since its your web application.
Here's an example of a basic request that you C program should parse:
GET /index.html HTTP/1.1
Host: www.example.com
And return a response with the requested content and response headers, such as:
HTTP/1.1 200 OK
Date: Mon, 23 May 2005 22:38:34 GMT
Server: Apache/1.3.3.7 (Unix) (Red-Hat/Linux)
Last-Modified: Wed, 08 Jan 2003 23:11:55 GMT
Etag: "3f80f-1b6-3e1cb03b"
Accept-Ranges: bytes
Content-Length: 438
Connection: close
Content-Type: text/html; charset=UTF-8
I may have already mentioned this but the HTTP protocol is really vast. Browsers with varying capabilities could access the site, and you would have to respond accordingly. Having said that, since it's all under your control, you could start small with perhaps a small subset of the requests/headers you'd like to handle, single-threaded, one request at a time, etc. and then build it out from there.
Like Kaleb said if C can be used in OS's and spaceships, then we can definitely write a web and application server with it :)