amphp / http-client

An advanced async HTTP client library for PHP, enabling efficient, non-blocking, and concurrent requests and responses.
https://amphp.org/http-client
MIT License
706 stars 66 forks source link

Disable FollowRedirects for request #367

Closed xpader closed 6 days ago

xpader commented 2 weeks ago

Is there any way to disable follow redirects only for a request?

May be should have an attribute to disable FollowRedirects interceptor?

Like:

$request = new Request($url);
$request->setAttribute('follow_redirects', false);
kelunik commented 1 week ago

No, this is currently not possible. Why not create two HttpClient instances?

xpader commented 1 week ago

I'm try to using one pool instance, use same connection pool. If using another instance, it will create new connection.

For example, request https://example.com/get-information to get some information, need follow redirect to get finally response, and request https://example.com/url-redirect don't follow redirect just parse redirect target url from header Location.

kelunik commented 6 days ago

You can still share the connection pool. I have just added an example to illustrate this: https://github.com/amphp/http-client/commit/7580dc20fe7d8c83ad5f453ac5995e8bfb5d1f45

xpader commented 6 days ago

Oh, so this can be done. I didn't expect it before, thank you.