Finally you are going to understand how internet works from the server side. The Hypertext Transfer Protocol was created in order to ensure a reliable way to communicate on a request/response base.
This protocol is used by servers and clients (usually browsers) to serve content and it is the backbone of the World Wide Web, still it is also used in many other cases that are far beyond the scope of this exercise.
Here you will learn the basics of the protocol and a good place to start could be the HTTP/1.1 RFC.
- The project must be written in
Rust. - You can use the
libccrate for functions asepollor equivalents and any other necessary system call that Rust do not implement natively. - You may need to use
unsafekeyword for some operations (don't abuse it).
You can't use crates that already implement server features like
tokioornix.
You goal is to write your very own server, which will use HTTP protocol to serve static web pages to browsers.
For your server you must guarantee the following behavior:
- It never crashes.
- All requests timeout if they are taking too long.
- It can listen on multiple ports and instantiate multiple servers at the same time.
- You use only one process and one thread.
- It receives a request from the browser/client and send a response using the
HTTPheader and body. - It is compatible with
HTTP/1.1protocol. - You can compare your results with
NGINXwhich will be used as the reference. - It is compatible with the last version of your chosen browser.
- It manages at least [
GET,POST,DELETE] methods. - It is able to receive file uploads made by the client.
- It handles cookies and sessions.
- You should create default error pages for at least the following error codes [400,403,404,405,413,500].
- It calls
epollfunction (or equivalent) only once for each client/server communication. - All reads and writes should pass by
epollor equivalent API. - All I/O operations should be non-blocking.
- You should manage chunked and unchunked requests.
- You should set the right status for each response.
- Based on the file extension the server will execute the corresponding
CGI(for example.phpor.py). - You need to implement only one
CGIof your choice. - You are allowed to fork a new process to run the
CGI. CGIexpects the file to process as first argument andEOFas end of the body.- Pay attention to the directory where the
CGIwill run for correct relative paths handling. - The
CGIwill checkPATH_INFOenvironment variable to define the full path.
In the file you should be able to specify the following:
- The host (server_address) and one or multiple ports for each server.
- The first server for a host:port will be the default if the "server_name" didn't match any other server.
- Path to custom error pages.
- Limit client body size for uploads.
- Setup routes with one or multiple of the following settings:
- Define a list of accepted HTTP methods for the route.
- Define HTTP redirections.
- Define a directory or a file from where the file should be searched (for example, if
/testis rooted to/usr/Desktop, the URL/test/my_page.htmlwill route to/usr/Desktop/my_page.html). - Define a default file for the route if the URL is a directory.
- Specify a
CGIto use for a certain file extension. - Turn on or off directory listing.
- Set a default file to answer if the request is a directory.
- No need to manage comments "(#)".
Routes won't need to support regular expressions.
There is no need to pass through
epollwhen reading the configuration file.
- Do stress tests with
siege -b [IP]:[PORT], it must stay available at all costs (availability should be up to 99.5, it will be tested during audits). - Create tests for as many cases as you can (redirections, bad configuration files, static and dynamic pages, default error pages and so on).
- You will be requested to provide and explain your tests during the audits.
- You can use the language you prefer to write tests, as long as they are exhaustive and the auditor can check their behavior.
- Test possible memory leaks before to submit the project.
- Once again, the server should never crash and never leak memory.
Attention:
siegeis a stressing tool, use it ONLY to test your own server. Do NEVER use it on any server/website without the owner's permission. If you do so you would have illegally DDoSed a server and could face serious troubles.
- Handle at least one more
CGI. - Rewrite the project in another programming language (can be
C++orC).