Repository navigation
AsyncRedirectExec: return the redirect response when the request entity can't be repeated - #945
Conversation
|
The fix looks reasonable and belongs in AsyncRedirectExec. However, I would like to see the non-repeatable entity case handled before redirect URI validation and redirect limit checks, consistently with the classic implementation. The regression test also needs to cover POST with 307/308 and method-changing 301/302/303 redirects. We should verify that the original response is delivered and the request entity is never replayed when it cannot be repeated. |
@shinseongsu The behavior of the async transport should be consistent with that of the classic one. Your current approach is correct. |
|
Thanks @arturobernalg, @ok2c. I moved the non-repeatable check up so it runs right after The test now sends a POST for 301, 302, 303, 307 and 308. It checks that the 3xx response comes back, that the body producer ran once, and that the redirect target never got a request. With the previous commit, the 301/302/303 cases fail on all four transports. Does that match what you had in mind for the method-changing codes? |
|
@shinseongsu Please squash the commits. |
…ty can't be repeated The non-repeatable check ran in completed(), after the response had already been replaced by a discarding consumer, so the exchange finished without a response and the future never completed. Do the check in handleResponse() right after isRedirected(), ahead of the redirect limit and location checks, like the classic RedirectExec. A POST with a non-repeatable entity now gets the 301/302/303 response back instead of being followed as a GET.
a9846b3 to
5cc6aed
Compare
|
@ok2c Squashed into a single commit. |
|
Cherry-picked to |
The async client never completes a request with a non-repeatable entity when the server answers 307 or 308 (or 301/302 for a non-POST method). Neither the callback nor the future is ever called.
TimeoutException, future never completesTimeoutException, future never completesSame with
ReactiveEntityProducer. I first hit it through Spring'sWebClientwithHttpComponentsClientHttpConnector: request bodies there are always non-repeatable, so a POST to an endpoint that answers 308 (http -> https, or a trailing-slash redirect) just hangs until a timeout cancels it.AsyncRedirectExecdecides inhandleResponse()that the response is a redirect and hands back a discarding consumer, so the response never reaches the caller. Only incompleted()does it notice the entity can't be repeated, and then it callsasyncExecCallback.completed()without a response. The classicRedirectExecreturns the redirect response in this case, andAsyncHttpRequestRetryExecdoes the same for a non-repeatable entity (asyncExecCallback.handleResponse(response, entityDetails)).The change moves the repeatability check into
handleResponse(), after the method rewrite, and passes the response on when the redirect can't be followed. A 303, or a 301/302 of a POST, is still followed because the redirect is a GET without the entity.Added
testRedirectNonRepeatableEntity(301 / 307 / 308) toAbstractHttpAsyncRedirectsTest. It times out on master and passes with the change.I went with returning the redirect response because that's what the classic client already does. Other clients handle this case in one of two ways:
RetryAndFollowUpInterceptor, one-shot body), Gonet/http(redirectBehavior,GetBodynil), Rust reqwest (tower-httpFollowRedirect, body not cloneable).UnrewindableBodyError), and fetch per the Fetch spec, e.g. undici in Node.js (network error when the body has no source).Is returning the response what you want here, or would you prefer the exchange to fail with an exception (for example a
RedirectException) so the caller can tell the redirect wasn't followed?