Ticket #4185 enhancement new
twisted.web.client.HTTPClient should expose the HTTP status as an integer
| Reported by: | nejucomo | Owned by: | |
|---|---|---|---|
| Priority: | low | Milestone: | |
| Component: | web | Keywords: | |
| Cc: | exarkun | Branch: | |
| Author: | Launchpad Bug: |
Description
The twisted.web.http.Request.setResponseCode() method requires an int argument to represent the HTTP status code to send to a client.
On the other hand, the twisted.web.client.HTTPClientFactory.deferred errback fires with a Failure whose .value.status contains a string representing the HTTP status code in the response from a server. (The errback fires when this status is an error status, such as a 404.)
I assumed I could pass the contents of a Failure to a Request (server-side response) but this raised a type error. A simplified example of the code would look like this:
def errback(reason):
assert the_reason_represents_a_404_error_response(reason)
myRequest.setResponseCode(reason.value.status)
cfac = HTTPClientFactory('http://www.google.com/nonexistent_path_wombat')
cfac.deferred.addCallbacks(normalHandler, errback)
reactor.connectTCP(cfac.host, cfac.port, cfac)
Change History
Note: See
TracTickets for help on using
tickets.
