Split the request-specific code from HttpConnection.

Also added a number of CHECKs and comments to clarify the logic.