PluginProbe
Media Cloud Sync / 1.3.11
Media Cloud Sync v1.3.11
1.4.0 1.3.12 1.3.11 1.3.10 trunk 1.0.0 1.0.1 1.0.2 1.0.3 1.1.0 1.1.1 1.2.0 1.2.10 1.2.11 1.2.12 1.2.13 1.2.2 1.2.3 1.2.4 1.2.5 1.2.6 1.2.7 1.2.8 1.2.9 1.3.0 All 34 releases
media-cloud-sync / includes / sdk / s3 / GuzzleHttp / Handler / EasyHandle.php

EasyHandle.php in Media Cloud Sync 1.3.11, at includes/sdk/s3/GuzzleHttp/Handler/EasyHandle.php

92 lines 2.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Dudlewebs\WPMCS\s3\GuzzleHttp\Handler;
4
5 use Dudlewebs\WPMCS\s3\GuzzleHttp\Psr7\Response;
6 use Dudlewebs\WPMCS\s3\GuzzleHttp\Utils;
7 use Dudlewebs\WPMCS\s3\Psr\Http\Message\RequestInterface;
8 use Dudlewebs\WPMCS\s3\Psr\Http\Message\ResponseInterface;
9 use Dudlewebs\WPMCS\s3\Psr\Http\Message\StreamInterface;
10 /**
11 * Represents a cURL easy handle and the data it populates.
12 *
13 * @internal
14 */
15 final class EasyHandle
16 {
17 /**
18 * @var resource|\CurlHandle cURL resource
19 */
20 public $handle;
21 /**
22 * @var StreamInterface Where data is being written
23 */
24 public $sink;
25 /**
26 * @var array Received HTTP headers so far
27 */
28 public $headers = [];
29 /**
30 * @var ResponseInterface|null Received response (if any)
31 */
32 public $response;
33 /**
34 * @var RequestInterface Request being sent
35 */
36 public $request;
37 /**
38 * @var array Request options
39 */
40 public $options = [];
41 /**
42 * @var int cURL error number (if any)
43 */
44 public $errno = 0;
45 /**
46 * @var \Throwable|null Exception during on_headers (if any)
47 */
48 public $onHeadersException;
49 /**
50 * @var \Exception|null Exception during createResponse (if any)
51 */
52 public $createResponseException;
53 /**
54 * Attach a response to the easy handle based on the received headers.
55 *
56 * @throws \RuntimeException if no headers have been received or the first
57 * header line is invalid.
58 */
59 public function createResponse() : void
60 {
61 [$ver, $status, $reason, $headers] = HeaderProcessor::parseHeaders($this->headers);
62 $normalizedKeys = Utils::normalizeHeaderKeys($headers);
63 if (!empty($this->options['decode_content']) && isset($normalizedKeys['content-encoding'])) {
64 $headers['x-encoded-content-encoding'] = $headers[$normalizedKeys['content-encoding']];
65 unset($headers[$normalizedKeys['content-encoding']]);
66 if (isset($normalizedKeys['content-length'])) {
67 $headers['x-encoded-content-length'] = $headers[$normalizedKeys['content-length']];
68 $bodyLength = (int) $this->sink->getSize();
69 if ($bodyLength) {
70 $headers[$normalizedKeys['content-length']] = $bodyLength;
71 } else {
72 unset($headers[$normalizedKeys['content-length']]);
73 }
74 }
75 }
76 // Attach a response to the easy handle with the parsed headers.
77 $this->response = new Response($status, $headers, $this->sink, $ver, $reason);
78 }
79 /**
80 * @param string $name
81 *
82 * @return void
83 *
84 * @throws \BadMethodCallException
85 */
86 public function __get($name)
87 {
88 $msg = $name === 'handle' ? 'The EasyHandle has been released' : 'Invalid property: ' . $name;
89 throw new \BadMethodCallException($msg);
90 }
91 }
92