Skip to content

Commit bb957be

Browse files
committed
Rework seekable body documentation with the split into two plugins
1 parent 3b70803 commit bb957be

File tree

3 files changed

+31
-26
lines changed

3 files changed

+31
-26
lines changed

plugins/always-seekable-body-plugin.rst

Lines changed: 0 additions & 25 deletions
This file was deleted.

plugins/index.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ request or you can even start a completely new request. This gives you full cont
1010

1111
introduction
1212
build-your-own
13-
always-seekable-body-plugin
13+
seekable-body-plugins
1414
authentication
1515
cache
1616
content-length

plugins/seekable-body-plugins.rst

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
Seekable Body Plugins
2+
=====================
3+
4+
``RequestSeekableBodyPlugin`` and ``ResponseSeekableBodyPlugin`` ensure that body used in request and response is always seekable.
5+
This allows a lot of components, reading the stream, to rewind it in order to be used later by another component::
6+
7+
use Http\Discovery\HttpClientDiscovery;
8+
use Http\Client\Common\PluginClient;
9+
use Http\Client\Common\Plugin\RequestSeekableBodyPlugin;
10+
use Http\Client\Common\Plugin\ResponseSeekableBodyPlugin;
11+
12+
$options = [
13+
'use_file_buffer' => true,
14+
'memory_buffer_size' => 2097152,
15+
];
16+
$requestSeekableBodyPlugin = new RequestSeekableBodyPlugin($options);
17+
$responseSeekableBodyPlugin = new ResponseSeekableBodyPlugin($options);
18+
19+
$pluginClient = new PluginClient(
20+
HttpClientDiscovery::find(),
21+
[$requestSeekableBodyPlugin, $responseSeekableBodyPlugin]
22+
);
23+
24+
Those plugins support the following options (which are passed to the ``BufferedStream`` class):
25+
26+
* ``use_file_buffer``: Whether it should use a temporary file to buffer the body of a stream if it's too big
27+
* ``memory_buffer_size``: Maximum memory to use for buffering the stream before it switch to a file
28+
29+
``RequestSeekableBodyPlugin`` should be added in top of your plugins, then next plugins can seek request body (i.e. for logging purpose).
30+
``ResponseSeekableBodyPlugin`` should be the last plugin, then previous plugins can seek response body.

0 commit comments

Comments
 (0)