@@ -66,6 +66,7 @@ mess with most of the low-level details.
6666 * [ withRejectErrorResponse()] ( #withrejecterrorresponse )
6767 * [ withBase()] ( #withbase )
6868 * [ withProtocolVersion()] ( #withprotocolversion )
69+ * [ withResponseBuffer()] ( #withresponsebuffer )
6970 * [ ~~ withOptions()~~ ] ( #withoptions )
7071 * [ ~~ withoutBase()~~ ] ( #withoutbase )
7172 * [ ResponseInterface] ( #responseinterface )
@@ -1196,6 +1197,43 @@ Notice that the [`Browser`](#browser) is an immutable object, i.e. this
11961197method actually returns a * new* [ ` Browser ` ] ( #browser ) instance with the
11971198new protocol version applied.
11981199
1200+ #### withResponseBuffer()
1201+
1202+ The ` withRespomseBuffer(int $maximumSize): Browser ` method can be used to
1203+ change the maximum size for buffering a response body.
1204+
1205+ The preferred way to send an HTTP request is by using the above
1206+ [ request methods] ( #request-methods ) , for example the [ ` get() ` ] ( #get )
1207+ method to send an HTTP ` GET ` request. Each of these methods will buffer
1208+ the whole response body in memory by default. This is easy to get started
1209+ and works reasonably well for smaller responses.
1210+
1211+ By default, the response body buffer will be limited to 16 MiB. If the
1212+ response body exceeds this maximum size, the request will be rejected.
1213+
1214+ You can pass in the maximum number of bytes to buffer:
1215+
1216+ ``` php
1217+ $browser = $browser->withResponseBuffer(1024 * 1024);
1218+
1219+ $browser->get($url)->then(function (Psr\Http\Message\ResponseInterface $response) {
1220+ // response body will not exceed 1 MiB
1221+ var_dump($response->getHeaders(), (string) $response->getBody());
1222+ });
1223+ ```
1224+
1225+ Note that the response body buffer has to be kept in memory for each
1226+ pending request until its transfer is completed and it will only be freed
1227+ after a pending request is fulfilled. As such, increasing this maximum
1228+ buffer size to allow larger response bodies is usually not recommended.
1229+ Instead, you can use the [ ` requestStreaming() ` method] ( #requeststreaming )
1230+ to receive responses with arbitrary sizes without buffering. Accordingly,
1231+ this maximum buffer size setting has no effect on streaming responses.
1232+
1233+ Notice that the [ ` Browser ` ] ( #browser ) is an immutable object, i.e. this
1234+ method actually returns a * new* [ ` Browser ` ] ( #browser ) instance with the
1235+ given setting applied.
1236+
11991237#### ~~ withOptions()~~
12001238
12011239> Deprecated since v2.9.0, see [ ` withTimeout() ` ] ( #withtimeout ) , [ ` withFollowRedirects() ` ] ( #withfollowredirects )
0 commit comments