igrigorik/em-http-request — pull request #220 by ianejames (2013-03-04 23:06:50+00:00)
Title: Redirect by status

The HttpClient class should use the HTTP status code to determine whether to follow a redirect. Currently the presence of a "Location" header is used. There are instances where a Location header is included in a response but should not be followed, for example after a 201 Created response from a server.

This was causing our server to be hit twice -- once with the original POST request to /users, then another POST to /users/58 (for example) with the original parameters. Of course, the response to the second request was a 405 Method not allowed with blank body.

There are two preliminary commits to the HttpResponseHeader class. The first one just memoizes the integer status value so that it doesn't get repeatedly typecast. The second one adds methods for HTTP status code class, only one of which is used in the final commit, but they're all included for completeness.

The final commit fixes the issue, and adds test coverage for this case.