Assignment 6

The following assignment is due Thursday 8/30 by 8:00 PM. You'll need to submit a .zip file containing a Cargo project named hw6 in Gradescope. You can get the setup with:

cargo new hw6

You can put your solutions into the file hw6/src/main.rs. Please make sure to run cargo clean before submitting, i.e., don't sumbit a target directory or a .git directory.

Given we just had the midterm, I've decided that assignment 6 should be simple and low effort. In this assignment, all you have to do: implement the single-threaded web server in RPL 21.1. The motivation is three-fold:

The one thing we'll do to make this more interesting: we'll create a better interface for requests and responses using all the nice type features of Rust:

enum Request {
    Get(PathBuf), // does not include headers or message
}

enum ParseError {
    MissingMethod,
    UnknownMethod,
    MissingPath,
    MissingVersion,
    UnknownVersion,
    ExtraItem,
}

impl FromStr for Request {
    type Err = ParseError;

    fn from_str(s: &str) -> Result<Request, ParseError> {
        todo!()
    }
}

enum Status {
    Ok,
    NotFound,
}

impl fmt::Display for Status {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> Result<(), fmt::Error> {
        todo!()
    }
}

struct Response {
    status: Status,
    contents: String,
}

impl Response {
    fn new(status: Status, contents: String) -> Response {
        Response { status, contents }
    }
}

impl fmt::Display for Response {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> Result<(), fmt::Error> {
        todo!()
    }
}

As usual, this assignment is a bit open ended. Do as much error handling as you feel comfortable doing. A couple things to look at in the standard library: