Homework 3ΒΆ

Due by noon on Thursday, Jan 30th.

  1. Branches, etc.

    At your leisure, merge hw2 into your master. (This can be done by merging the pull request). If this has been done correctly, visiting your default github page for cse491-serverz should show you the code from hw2. You may have trouble merging; I’ll produce a video over the weekend on how to do this. Until then, just work on the hw2 branch.)

    Your master branch should now contain hw2.

    To hand in this homework, put everything on a new branch, hw3 (‘git checkout -b hw3’), and push that to github. Set up a pull request between hw3 and your master branch (again, matching to hw2) and don’t merge the pull request – just leave it there.

  2. Form parsing/GET.

    Use the ‘urlparse’ library (included with Python 2.7) to parse the ‘path’ component of HTTP requests so that GET form data can be handled. You should end up using both the ‘urlparse’ and ‘parse_qs’ functions.

    See the GET footnotes for more information on the basics.

    Here is an HTML form that will generate an HTTP GET with form values:

    <form action='/submit' method='GET'>
    <input type='text' name='firstname'>
    <input type='text' name='lastname'>
    
    </form>
    

    Serve this form via your Web server (e.g. as ‘/form’) and then implement code to take ‘/submit’ requests and return a page containing the string, “Hello Mr. $firstname $lastname.” (You might look up Python string interpolation to figure out how to substitute variables, although if you want to be a bad programmer you can just use ‘+’ to concatenate strings.)

    In addition, create an automated test verifying the results of the form parsing. (i.e. create a fake GET request with firstname/lastname set, and assert that the page contains the correct response containing that firstname/lastname).

  3. Form parsing/POST/content-type.

    Edit or copy the form to also do this via a POST, for request content-type of application/x-www-form-urlencoded. Note that for POST requests the content will be submitted as part of the content body, which for GET requests is empty; so you need to parse that.

    Also see: http://www.cs.tut.fi/~jkorpela/forms/methods.html

    You only need one form (so you can choose to do either a GET or a POST) but please make sure that both GET and POSTs can work in your HTTP server implementation. The best way to do this is to get both GET and POST working, and then make sure that you have automated tests for both; I expect to see tests for both.

  4. Refactor your main function.

    Split the different pages up into different functions, so that ‘/’ goes to (for example) ‘index(...)’. Try to make the functions all take the same set of parameters, for future purposes. You can still have a bunch of if/else statements in the main handle_connection function ;).

  5. Reminder: submit as a pull request, unmerged, from branch ‘hw3’ to branch ‘master’ (which contains hw2) on your github repo.

Previous topic

Day 7: Tuesday, January 28th, 2014

Next topic

Day 6: Thursday, January 23rd, 2014

This Page

Edit this document!

This file can be edited directly through the Web. Anyone can update and fix errors in this document with few clicks -- no downloads needed.

  1. Go to Homework 3 on GitHub.
  2. Edit files using GitHub's text editor in your web browser (see the 'Edit' tab on the top right of the file)
  3. Fill in the Commit message text box at the bottom of the page describing why you made the changes. Press the Propose file change button next to it when done.
  4. Then click Send a pull request.
  5. Your changes are now queued for review under the project's Pull requests tab on GitHub!

For an introduction to the documentation format please see the reST primer.