Socket HTTP Server, Step 2

Leveraging what you have learned about the HTTP protocol, you will improve the functionality of your simple HTTP server. Create a new branch in your http-server repository called “step2” in which to do your work.

Tasks

Implement a function called parse_request

  • The function should take a single argument which is the request from the client
  • The function should only accept GET requests, any other request should raise an appropriate Python error
  • The function should only accept HTTP/1.1 requests, a request of any other protocol should raise an appropriate Python error
  • The function should validate that a proper Host header was included in the request, if not, raise an appropriate Python error
  • If none of the conditions above arise, then the function should return the URI from the clients request

Update your response_error function to parameterize the error code and reason phrase. The return value should still be a well-formed HTTP error response, with the passed error code and reason phrase.

Update the server loop you built for step one:

  • pass the request you accumulate into your new parse_request function
  • handle any errors raised by building an appropriate HTTP error response
  • if no errors are raised, build an HTTP 200 OK response.
  • return the response you built to the client

Write tests for each goal before you write the code to achieve it. Make sure you have both unit tests to cover the functions you write, and functional tests that ensure that the server loop operates as expected.

Update your README file with an expanded description of the server you’re building. Include any sources or collaborations you used.

Submitting Your Work

When you are done and your tests are all passing, push your work to GitHub and submit a pull request from the step2 branch back to master. Copy the URL of the pull request. After you’ve created the pull request you may merge the step2 branch back to master.

Submit the URL of your pull request.

As with every primary submission, use the Comments feature for this submission to add questions, comments and reflections on the work you have done so far.