Skip to content

Add documentation for always seekable body plugin #251

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Feb 23, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions plugins/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ request or you can even start a completely new request. This gives you full cont

introduction
build-your-own
seekable-body-plugins
authentication
cache
content-length
Expand Down
30 changes: 30 additions & 0 deletions plugins/seekable-body-plugins.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
Seekable Body Plugins
=====================

``RequestSeekableBodyPlugin`` and ``ResponseSeekableBodyPlugin`` ensure that body used in request and response is always seekable.
This allows a lot of components, reading the stream, to rewind it in order to be used later by another component::

use Http\Discovery\HttpClientDiscovery;
use Http\Client\Common\PluginClient;
use Http\Client\Common\Plugin\RequestSeekableBodyPlugin;
use Http\Client\Common\Plugin\ResponseSeekableBodyPlugin;

$options = [
'use_file_buffer' => true,
'memory_buffer_size' => 2097152,
];
$requestSeekableBodyPlugin = new RequestSeekableBodyPlugin($options);
$responseSeekableBodyPlugin = new ResponseSeekableBodyPlugin($options);

$pluginClient = new PluginClient(
HttpClientDiscovery::find(),
[$requestSeekableBodyPlugin, $responseSeekableBodyPlugin]
);

Those plugins support the following options (which are passed to the ``BufferedStream`` class):

* ``use_file_buffer``: Whether it should use a temporary file to buffer the body of a stream if it's too big
* ``memory_buffer_size``: Maximum memory to use for buffering the stream before it switch to a file

``RequestSeekableBodyPlugin`` should be added in top of your plugins, then next plugins can seek request body (i.e. for logging purpose).
``ResponseSeekableBodyPlugin`` should be the last plugin, then previous plugins can seek response body.
2 changes: 2 additions & 0 deletions spelling_word_list.txt
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ phpdoc
Puli
rebase
Semver
Seekable
seekable
sexualized
sublicense
sync
Expand Down