Serving the Web
For this homework set, you will implement a rudimentary web server in Rust.
The objective of this homework is to get to know Rust’s concurrency model and constructs.
Deadline Friday 13 March NOON.
web_server
GET <path_to_file> HTTP |
an 200 OK status, which starts a reply that serves the specified file;
a 400 Bad Request, which indicates that the command is not a properly formatted GET command;
a 403 Forbidden, which rejects a command because it specifies a file that is off-limits;
a 404 Not Found, which informs the client that the specified file does not exist.
HTTP/1.0 200 OK |
<name_of_web_server> |
Content-type: text/<plain_or_html> |
Content-Length: <number_of_bytes_sent> |
The remainder of a 200-message is the content of the specified file.
if the resulting path points to a file, the file is served with a 200-message unless its permissions do not allow so.
if the resulting path points to a directory, it is interpreted as pointing to one of these files: index.html, index.shtml, and index.txt. The first file found is served assuming it is accessible. Otherwise the path triggers a 404-message.
otherwise the server responds with an error message.
$ telnet 127.0.0.1 8080 |
Trying 127.0.0.1... |
Connected to localhost. |
Escape character is '^]'. |
GET /main.rs HTTP/1.0 |
|
HTTP/1.0 200 OK |
MFs_web_server |
Content-type: text/plain |
Content-Length: 2034... |
|
// This module implements a simplistic HTTP server. |
|
use std::io; |
use std::io::{TcpListener,TcpStream}; |
use std::io::{Listener,Acceptor}; |
use std::thread::Thread; |
use std::io::net::tcp; |
... |
... |