Project Summary
In this project, we took a look at the HTTP protocol as a Web server. The server program will receive two arguments:
1) the port number it should listen on for incoming connections, and
2) the directory out of which it will serve files (often called the document root in production Web servers).
Some Requirements:
- HTML, text, and image files should all display properly. You’ll need to return the proper HTTP Content-Type header in your response, based on the file ending. Also, other binary file types like PDFs should be handled correctly. You don’t need to handle everything on that list, but you should at least be able to handle files with html, txt, jpeg, gif, png, and pdf extensions.
- If asked for a file that does not exist, you should respond with a 404 error code with a readable error page, just like a Web server would. It doesn’t need to be fancy, but it should contain some basic HTML so that the browser renders something and makes the error clear.
- Some clients may be slow to complete a connection or send a request. Your server should be able to serve multiple clients concurrently, not just back-to-back.
- If the path requested by the client is a directory, you should handle the request as if it was for the file index.html inside that directory.
- The Web server should respond with a list of files when the user requests a directory that does not contain an index.html file.
- Common Gateway Interface (CGI) is a protocol for a web server to serve dynamic content using command-line interface programs. Your server must be able to serve basic CGI requests.
Topics Learned Upon Completion
- How to follow a network protocol. (In this case, HTTP)
- Socket programming and network programming in C
- Simple multi-threading in C using pthreads