~ballot/wordpress/openstack-objectstorage

« back to all changes in this revision

Viewing changes to vendor/guzzlehttp/guzzle/src/Adapter/StreamingProxyAdapter.php

  • Committer: Benjamin Allot
  • Date: 2020-07-02 16:31:38 UTC
  • Revision ID: benjamin.allot@canonical.com-20200702163138-qyk6njanak5uw2pg
Revert to revno 3

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<?php
 
2
 
 
3
namespace GuzzleHttp\Adapter;
 
4
 
 
5
/**
 
6
 * Sends streaming requests to a streaming compatible adapter while sending all
 
7
 * other requests to a default adapter.
 
8
 *
 
9
 * This, for example, could be useful for taking advantage of the performance
 
10
 * benefits of the CurlAdapter while still supporting true streaming through
 
11
 * the StreamAdapter.
 
12
 */
 
13
class StreamingProxyAdapter implements AdapterInterface
 
14
{
 
15
    private $defaultAdapter;
 
16
    private $streamingAdapter;
 
17
 
 
18
    /**
 
19
     * @param AdapterInterface $defaultAdapter   Adapter used for non-streaming responses
 
20
     * @param AdapterInterface $streamingAdapter Adapter used for streaming responses
 
21
     */
 
22
    public function __construct(
 
23
        AdapterInterface $defaultAdapter,
 
24
        AdapterInterface $streamingAdapter
 
25
    ) {
 
26
        $this->defaultAdapter = $defaultAdapter;
 
27
        $this->streamingAdapter = $streamingAdapter;
 
28
    }
 
29
 
 
30
    public function send(TransactionInterface $transaction)
 
31
    {
 
32
        return $transaction->getRequest()->getConfig()['stream']
 
33
            ? $this->streamingAdapter->send($transaction)
 
34
            : $this->defaultAdapter->send($transaction);
 
35
    }
 
36
}