Skip to content

Conversation

@mawinter69
Copy link
Contributor

@mawinter69 mawinter69 commented Dec 14, 2025

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

  • Make sure you are opening from a topic/feature/bugfix branch (right side) and not your main branch!
  • Ensure that the pull request title represents the desired changelog entry
  • Please describe what you did
  • Link to relevant issues in GitHub or Jira
  • Link to relevant pull requests, esp. upstream and downstream changes
  • Ensure you have provided tests that demonstrate the feature works or the issue is fixed

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.
@mawinter69 mawinter69 requested a review from a team as a code owner December 14, 2025 15:44
Copy link
Contributor

@MarkEWaite MarkEWaite left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@MarkEWaite MarkEWaite merged commit 6569ddf into jenkinsci:master Dec 15, 2025
17 checks passed
@MarkEWaite MarkEWaite added the bug label Dec 15, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants