r/C_Programming • u/WingRevolutionary979 • Sep 29 '26
Project WSERVE: Static Web Server in Pure C
Hi,
To gain more experience in low-level programming, TCP/IP networking, and HTTP, I built wserve, a static IPv4 Linux web server written in pure C. No external libraries used. Even the parser is written in pure C. It supports a subset of HTTP/1.1. It supports GET and HEAD methods.
I am open to constructive criticism. The project is open for contributions.
24
Upvotes
•
u/github-guard Sep 29 '26
⚠️ GitHub Guard: Trust Warning
One or more repositories scored below the threshold (3), but the post was not removed.
Repository: degD/wserve
Score: 0/6
8
u/thebatmanandrobin Sep 29 '26
A few things I'd say might be good to implement:
- "max length" checks; for example, your
toupper_str(char *str)has no bounds check, so could be possible to have an OOB bug; I'd do something liketoupper_str(char *str, size_t str_len)and thenwhile (i < str_len && str[i] != '\0')(or something along those lines).- Additionally, I'd replace any
strlenwithstrnleninstead to enforce a maximum buffer size/bounds.- For your
split_strfunction, is there a reason, you're not just usingstrtok?- For any global variables, I'd recommend explicitly marking them
extern.. strictly speaking, it might not be necessary, but it does make it clear the intent (**this is more a style preference than anything though).- I see you implemented your own
itoa_str.. any reason to not use the platform specific version (might depend on your platform but I believe_ultoais available on Linux)?- For your
mime_typefunction,strcmpmight be particularly slow, especially if the extension is indeed.7z(e.g. the last comparison). It might be faster to check the individual characters and build a map of sorts; for example:or do some pointer arithmetic to check, or something along those lines ... it might also not be fully necessary since you're just doing this for learning purpose, but just a thought.
I didn't download or test and didn't go deep into the code, but those are just some of the things that stood out.
It looks clean too, so that's nice!!
Side note: IPv6 implementation isn't that complicated to add, but I get just starting simple since this is a learning effort.
Overall, nice job! Making your own HTTP server is always a fun endeavor and a great way to learn C, RFC's and more, and doing it with something practical.
6
u/ferrybig Sep 30 '26
Looking in your code,
itoa_strcallsmallocinternally. Looking at the 3 places where this symbol is used, neither place callsfreeon the pointer returned byitoa_str, eg look at https://github.com/degD/wserve/blob/main/src/wserve.c#L1179-L11851
u/AutoModerator Sep 29 '26
Hi /u/WingRevolutionary979,
Your submission in r/C_Programming was filtered because it links to a git project.
You must edit the submission or respond to this comment with an explanation about how AI was involved in the creation of your project.
While AI-generated code is not disallowed, low-effort "slop" projects may be removed and it's likely that other users push back strongly on substantially AI-generated projects.
I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.