[JENKINS-76335] Allow redirect on GET and HEAD only #229
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
In Apache http client 5, the behavior of the DefaultRedirectStrategy has changed. With httpclient4 a redirect was only done on GET and HEAD requests, using the same method. In httpclient 5 a redirect is done for all methods and all redirect status codes. But a POST request is converted to a GET for 301 and 302 codes. Also a redirect is only done when the url is on the same server:port or when no cookies and authorization headers are included.
This change implements a new RedirectStrategy, that limits redirects to GET and HEAD as in client 4 but also keeps the enhanced security of not following redirects then the server/port changes and cookies/authorization is included.
This should fix JENKINS-76335 while not breaking the fix for JENKINS-76280
In JENKINS-76280 the user was doing POST requests so client was not following in client 4, but was following gith a GET in client 5. In JENKINS-76335 the user was doing a GET request so the client was following the redirect in client 4, but the fix for JENKINS-76280 disabled redirects completely thus breaking the GET requests.
Testing done
Added a unit test that verifies that a POST with 302 is not redirected but a GET with 302 is redirected.
The GET test fails without the fix.
Submitter checklist