Ask HN: Resources for Building a Webserver in C?
21–30 of 67 posts
Re: Ask HN: Resources for Building a Webserver in C?
#22"Write a tiny web server in C" was a standard exercise when I was in high school, and later again in university. I think I did that at least 3 times as an assignment so far. I reused the final version for a different university exercise instead of bothering with Tomcat as I was required, and back in 2015, dumped the end result here: https://github.com/AgentD/websrv where I kept adding to it for a while for fun. The H…
Re: Ask HN: Resources for Building a Webserver in C?
#23Earlier quoted context omitted.
conceptually things are pretty limited - this is really simple if you are just playing around, and are just doing http 1 o bind a socket o manage incoming connections o parse http headers o 'routing' - demultiplex handlers based on URL o encode response unless its a little embedded thing one usually uses some kind of select/epoll machinery to multiplex the work on each channel. I guess thread-per-request is another m…
A little context: I'm specifically interested in compressing my analytics stack. I'm currently interacting with HTTP Messages at a higher level. The problem, as I see it, is the webserver is already doing this work but without useful output. I'd like to implement my analytics paradigm natively at the webserver level.
Re: Ask HN: Resources for Building a Webserver in C?
#24Earlier quoted context omitted.
conceptually things are pretty limited - this is really simple if you are just playing around, and are just doing http 1 o bind a socket o manage incoming connections o parse http headers o 'routing' - demultiplex handlers based on URL o encode response unless its a little embedded thing one usually uses some kind of select/epoll machinery to multiplex the work on each channel. I guess thread-per-request is another m…
A little context: I'm specifically interested in compressing my analytics stack. I'm currently interacting with HTTP Messages at a higher level. The problem, as I see it, is the webserver is already doing this work but without useful output. I'd like to implement my analytics paradigm natively at the webserver level.
Sounds like something nginx might handle via lua scripting?
Otherwise, maybe you want: https://github.com/lammertb/libhttp
Or you might want to look at either of:
https://www.acme.com/software/thttpd/
https://github.com/openbsd/src/tree/master/usr.sbin/httpd
If you really want to build (another) web server in C.
Not entirely clear why want to use C for this, though?
Re: Ask HN: Resources for Building a Webserver in C?
#25Short source code, excludes edge cases, but useful to understand the gist of web servers.
https://www.ibm.com/support/pages/how-does-webserver-actuall...
Re: Ask HN: Resources for Building a Webserver in C?
#26Re: Ask HN: Resources for Building a Webserver in C?
#27For embedded: https://github.com/cesanta/mongoose/
Re: Ask HN: Resources for Building a Webserver in C?
#28Earlier quoted context omitted.
A little context: I'm specifically interested in compressing my analytics stack. I'm currently interacting with HTTP Messages at a higher level. The problem, as I see it, is the webserver is already doing this work but without useful output. I'd like to implement my analytics paradigm natively at the webserver level.
I'm not sure I follow - you want a smart, small webserver that takes in a http request and updates an analytic store based on headers? Sounds like something nginx might handle via lua scripting? Otherwise, maybe you want: https://github.com/lammertb/libhttp Or you might want to look at either of: https://www.acme.com/software/thttpd/ https://github.com/openbsd/src/tree/master/usr.sbin/httpd If you really want to buil…
but I have to agree about C. unless the whole point is to ingrate with some existing codebase, there are several language choices which should turn this from a day or two of work to an hour or two - with a more robust outcome
Re: Ask HN: Resources for Building a Webserver in C?
#29Beej's guide to network programming: https://beej.us/guide/bgnet/
This guide is great for introducing the bsd socket api but this is really not the API you want to use if you want to create a production quality web server in C in 2022. You need the uring io API.
https://unixism.net/loti/tutorial/webserver_liburing.html
(and maybe the older tutorial too):
https://unixism.net/2019/04/linux-applications-performance-i...
Re: Ask HN: Resources for Building a Webserver in C?
#30I recommend swapping out C for a safer&more productive language.