Project 2 tips

2021/10/14

You are free to implement project 2 any way you want, as long as it meets the specification. However, I wanted to pass along one potential strategy that you may find helpful.

One approach you can take to the project is to develop it in pieces, so that you can debug and test each piece as you go. That way, you don’t have to try to debug a huge system, which can be very difficult!

The goal here is to make a web server that works “end to end” very quickly, even though its features are very very limited. Then you add one feature at a time, so you can test as you go.

As an example, consider the following set of milestones for your server:

  1. Your server accepts incoming connections and just prints out to the screen whatever the client sends (we went over code that does this in class). This way, you should be able to see the HTTP request and headers from the client on your terminal.
  2. Next, have your server simply send to the client a “static” HTTP response no matter what request it sends. For example, an HTTP 200 OK response with a Content-Type of “text/html” and an appropriate Content-Length, where the body of the response is a very simple HTML page (I had one in my slides during class, though examples of HTML documents are easily found on the web)
  3. Now, instead of sending a static HTML page back to the client, generate an HTTP 200 OK response that sends the headers back as the body of a “text/html” document. In a sense, at this point you’ve implemented something very similar to server3.go!
  4. Now that you have a server that simply replies to the client with the request that the client sent, you can start to work on your parsing and framing code. Have you server modify the HTML you send back to, for example, highlight the URL, or some of the headers you’re supposed to handle.
  5. Once you’ve identified the URL, you can return (as an HTML document) to the client information about the file, such as whether it exists or not, or what its size is
  6. At this point, you can fully implment code for 200 and 404 return types, and complete the project.

Again, this isn’t the only way to implement the project but one that some might find helpful.