Rewrite the parsing mechanism for requests

This commit rewrites much of the parsing code for the
HTTP request. It also adds a few test cases to make
sure that it's working properly.