reqwest icon indicating copy to clipboard operation
reqwest copied to clipboard

feat: Add request level redirect policy config

Open Xuanwo opened this issue 7 months ago • 4 comments

This PR is part of https://github.com/seanmonstar/reqwest/issues/2641, and will close https://github.com/seanmonstar/reqwest/pull/2440 and https://github.com/seanmonstar/reqwest/issues/353, maybe relate to https://github.com/seanmonstar/reqwest/pull/2617

  • close https://github.com/seanmonstar/reqwest/pull/2440
  • close https://github.com/seanmonstar/reqwest/issues/353

This PR has the following changes:

  • Change PolicyKind::Custom from Box to Arc to make it Clone. That's required by inserting into http::Extensions
  • Introduce config::RedirectPolicy
  • Add public API Request::redirect and Request::redirect_mut

There are some chore changes (I'm open to move them to a seperate PR)

  • Change all usage of config from Xxx to config::Xxx to make it more clear.
  • Move Request::version to front for better API organization.

Xuanwo avatar Apr 30 '25 03:04 Xuanwo

Just noting that this might conflict with #2576 that someone else is actively working on.

seanmonstar avatar Apr 30 '25 13:04 seanmonstar

Just noting that this might conflict with #2576 that someone else is actively working on.

Thank you for your note.

My motivation for choosing to work on redirect::Policy is that it's a complex struct rather than a simple Duration. By using this struct, I can evaluate whether my previous configuration design is effective.

Another reason is that this is a feature request that others have also asked for. If we can merge this first, it will help us address those related issues.

I'm fine to begin this work once https://github.com/seanmonstar/reqwest/issues/2576 has been resolved if you prefer. It's clear that if https://github.com/seanmonstar/reqwest/pull/2617 is merged as it currently stands, incorporating it at the request level could become more complicated.

Xuanwo avatar May 01 '25 05:05 Xuanwo

@Xuanwo Do you have any new ideas for integrating https://github.com/seanmonstar/reqwest/pull/2617? HyperClient and RedirectPolicy are wrapped into FollowRedirect. If RedirectPolicy is set at the request level, it means that the FollowRedirect wrapper needs to be recreated every time

0x676e67 avatar May 28 '25 04:05 0x676e67

@Xuanwo Do you have any new ideas for integrating #2617? HyperClient and RedirectPolicy are wrapped into FollowRedirect. If RedirectPolicy is set at the request level, it means that the FollowRedirect wrapper needs to be recreated every time

I'll take another look when I have some time. However, since the wrapper itself doesn't add much overhead, it may be acceptable to recreate it each time.

Xuanwo avatar May 28 '25 04:05 Xuanwo