472
|
|
|
Jason Gerard DeRose |
|
4 years ago
|
|
|
471
|
|
|
Jason Gerard DeRose |
|
4 years ago
|
|
|
470
|
|
|
Jason Gerard DeRose |
|
6 years ago
|
|
|
469
|
|
|
Jason Gerard DeRose |
|
6 years ago
|
|
|
468
|
|
|
Jason Gerard DeRose |
|
6 years ago
|
|
|
467
|
|
|
Jason Gerard DeRose |
|
6 years ago
|
|
|
466
|
|
|
Jason Gerard DeRose |
|
6 years ago
|
|
|
465
|
|
|
Jason Gerard DeRose |
|
6 years ago
|
|
|
464
|
|
|
Jason Gerard DeRose |
0.18.0 |
7 years ago
|
|
|
463
|
|
|
Jason Gerard DeRose |
|
7 years ago
|
|
|
462
|
|
|
Jason Gerard DeRose |
|
7 years ago
|
|
|
461
|
|
|
Jason Gerard DeRose |
|
7 years ago
|
|
|
460
|
|
|
Jason Gerard DeRose |
|
7 years ago
|
|
|
459
|
|
|
Jason Gerard DeRose |
|
7 years ago
|
|
|
458
|
|
|
Jason Gerard DeRose |
|
7 years ago
|
|
|
457
|
|
|
Jason Gerard DeRose |
|
7 years ago
|
|
|
456
|
|
|
Jason Gerard DeRose |
|
7 years ago
|
|
|
455
|
|
|
Jason Gerard DeRose |
|
7 years ago
|
|
|
454
|
|
Cleanup close semantics, fixing Microfiber's automatic request retry.
If an exception is caught when reading an incoming `Body` or `ChunkedBody`, these classes will now call `SocketWrapper.close()` before raising the exception.
Because the `Connection.closed` attribute now returns the value of the internal `SocketWrapper.closed` instance attribute, this provides a way for the `Body` and `ChunkedBody` classes to convey the closed connection state to other consumers of the `SocketWrapper` instance. For example, this is a nice pattern for automatically retrying a failed request (by creating a new connection):
>>> def request_with_retry(method, uri, headers, body, client, conn=None): ... for retry in range(3): ... try: ... if conn is None or conn.closed: ... conn = client.connect() ... return (conn.request(method, uri, headers, body), conn) ... except ConnectionError as e: ... pass ... raise e ...
Prior to this commit, a `ConnectionError` raised while reading a `Body` or `ChunkedBody` would put the body into an error state, but without out any means to notify the `Connection` that the underlying socket is either already closed, or should be closed immediately because the HTTP stream is likely in an inconsistent state.
So `Connection.closed` would be `False`, meaning that the above retry loop wont create a new connection, and then when you call `Connection.request()` using the preexisting connection it would raise a `ValueError` complaining that you didn't fully consume your previous response body before making another request. Finally, as `ValueError` isn't a `ConnectionError` subclass, we bomb out of the retry loop without actually creating a new connection or attempting the request again.
The internal `_handle_requests()` function provides the server-side equivalent.
|
Jason Gerard DeRose |
|
7 years ago
|
|
|
453
|
|
|
Jason Gerard DeRose |
|
7 years ago
|
|
|