provide the implementation of a minimal HTTP web server in C that serves the content of a given directory. It should target Linux. listening port number and home directory will be given in command line arguments.
Assistant
To create a minimal HTTP web server in C that serves the content of a given directory on Linux, you can use the socket API for networking and open, read, and send system calls for file operations. Below is a simple implementation that takes the listening port number and home directory as command line arguments.
This will start the server listening on port 8080 and serving files from /path/to/home/directory.
Notes
This implementation is very basic and does not handle many edge cases or security concerns such as directory traversal attacks.
It only supports GET requests and serves files or directory listings.
Error handling is minimal, and the server will stop on any error.
This server is single-threaded and can only handle one request at a time. For a production environment, consider using multi-threading or asynchronous I/O.
“provide the implementation of a minimal HTTP web server in C that serves the content of….” Conversation with deepseek-v2-api-0628, from the LMArena Human Preference 100K dataset. The Chat Archive, 2026. https://thechatarchive.com/c/01m850fy1r7aenrfpkd9y2y60c