@@ -21,11 +21,10 @@ implementations for [PSR-17 (HTTP Factories)](https://www.php-fig.org/psr/psr-17
21
21
$client = new \Aternos\CurlPsr\Psr18\Client();
22
22
```
23
23
24
- When creating a client, you can optionally provide a PSR-17 ` ResponseFactoryInterface ` instance. By default,
25
- the client will use the ` Aternos\CurlPsr\Psr17\Psr17Factory ` class included in this library.
24
+ When creating a client, you can optionally provide PSR-17 ` ResponseFactoryInterface ` and ` UriFactoryInterface ` instances.
25
+ By default, the client will use the ` Aternos\CurlPsr\Psr17\Psr17Factory ` class included in this library.
26
26
27
- Additionally, you can pass an optional ` CurlHandleFactoryInterface ` instance as the second argument,
28
- which is mainly used for testing purposes.
27
+ Additionally, you can pass an optional ` UriResolverInterface ` instance, which is used to resolve redirect targets.
29
28
30
29
### Configuring the client
31
30
@@ -52,7 +51,34 @@ $client->setProgressCallback(function (
52
51
});
53
52
```
54
53
54
+ #### Custom cURL options
55
+
56
+ You can set custom cURL options using the ` setCurlOption ` method. Note that some options cannot be set, since they are
57
+ used internally by the client.
58
+
59
+ #### Redirects
60
+
61
+ The client will follow redirects by default. You can set the maximum number of redirects to follow using the
62
+ ` setMaxRedirects ` method. It is also possible to disable redirects using ` setFollowRedirects ` . The difference between
63
+ setting the maximum number of redirects to 0 and disabling redirects is that the former will throw an exception if a
64
+ redirect is received, while the latter will simply return the redirect response.
65
+
66
+ Only when status ` 303 See Other ` is received, the client will automatically change the request method to ` GET ` and
67
+ remove the request body. Historically, this behavior was also sometimes present for ` 301 ` and ` 302 ` , so it is possible
68
+ to enable it for other status codes using the ` setRedirectToGetStatusCodes ` method.
69
+
70
+ Status ` 300 Multiple Choices ` will only be treated as a redirect if the ` Location ` header is present.
71
+ Otherwise, the response will be returned as is.
72
+
73
+ To manage how redirect targets are resolved, or limit what locations the client can be redirected to,
74
+ you can pass an instance of ` UriResolverInterface ` to the client constructor.
75
+
76
+ When a redirect response is received that does not prompt the client to change the request method to ` GET `
77
+ and the body stream cannot be rewound, an exception is thrown. This is because the client cannot resend the request
78
+ with the same body stream.
79
+
55
80
#### Progress callback
81
+
56
82
The progress callback function works the same way as the ` CURLOPT_PROGRESSFUNCTION ` in cURL,
57
83
except that it receives the PSR-7 request object instead of a cURL handle as the first argument.
58
84
Please note that the request object passed to the callback is not necessarily same instance that was
0 commit comments