wleeaf opened a new pull request, #904: URL: https://github.com/apache/httpcomponents-client/pull/904
A redirect whose `Location` is a relative reference with an empty path, such as `?page=2` or `#section`, is followed to the root of the server instead of the current resource. For example, a `302` from `http://host/app/list?page=1` with `Location: ?page=2` is followed to `http://host/?page=2`. RFC 3986 section 5.2.2 (example `"?y"` -> `"http://a/b/c/d;p?y"` in section 5.4.1) resolves it to `http://host/app/list?page=2`. `URIUtils.resolve` already handles this case correctly (`TestURIUtils.testResolve` covers `?y`, `?y#f` and `#s`). The problem is in `DefaultRedirectStrategy.createLocationURI`, which runs first and sets the path of any location with an empty path to `/`. That is right for an absolute URI (`http://BlahBlah` -> `http://blahblah/`, as `testCreateLocationURI` expects), but it turns `?page=2` into `/?page=2`. Resolution then treats that as an absolute path. The empty path is now only replaced when the location has a host, so relative references reach `URIUtils.resolve` unchanged. The behaviour for absolute locations and for relative references that have a path is the same as before. New tests in `TestDefaultRedirectStrategy`: - `testGetLocationUriRelativeQueryOnly`: `?b=2` from `http://localhost/stuff/index.html?a=1` gives `http://localhost/stuff/index.html?b=2`. - `testGetLocationUriFragmentOnly`: `#fragment` gives `http://localhost/stuff/index.html?a=1#fragment`. Both fail without the change (`http://localhost/?b=2` and `http://localhost/#fragment`). `mvn -pl httpclient5 verify` passes (1103 tests). I found this by running the classic client (5.6.5) with its default redirect handling against a local server that answers with RFC 3986 reference-resolution cases. The async client uses the same `DefaultRedirectStrategy`. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
