PluginProbe
Media Cloud Sync / 1.4.1
Media Cloud Sync v1.4.1
1.4.1 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 All 35 releases
← All changes | includes/sdk/s3/GuzzleHttp/Handler/EasyHandle.php +42 -18 1.0.21.4.1 View file →
@@ -2,8 +2,9 @@
2 2
3 3 namespace Dudlewebs\WPMCS\s3\GuzzleHttp\Handler;
4 4
5 5 use Dudlewebs\WPMCS\s3\GuzzleHttp\Psr7\Response;
6 +use Dudlewebs\WPMCS\s3\GuzzleHttp\Utils;
6 7 use Dudlewebs\WPMCS\s3\Psr\Http\Message\RequestInterface;
7 8 use Dudlewebs\WPMCS\s3\Psr\Http\Message\ResponseInterface;
8 9 use Dudlewebs\WPMCS\s3\Psr\Http\Message\StreamInterface;
9 10 /**
@@ -12,38 +13,54 @@
12 13 * @internal
13 14 */
14 15 final class EasyHandle
15 16 {
16 - /** @var resource cURL resource */
17 + /**
18 + * @var resource|\CurlHandle cURL resource
19 + */
17 20 public $handle;
18 - /** @var StreamInterface Where data is being written */
21 + /**
22 + * @var StreamInterface Where data is being written
23 + */
19 24 public $sink;
20 - /** @var array Received HTTP headers so far */
25 + /**
26 + * @var array Received HTTP headers so far
27 + */
21 28 public $headers = [];
22 - /** @var ResponseInterface Received response (if any) */
29 + /**
30 + * @var ResponseInterface|null Received response (if any)
31 + */
23 32 public $response;
24 - /** @var RequestInterface Request being sent */
33 + /**
34 + * @var RequestInterface Request being sent
35 + */
25 36 public $request;
26 - /** @var array Request options */
37 + /**
38 + * @var array Request options
39 + */
27 40 public $options = [];
28 - /** @var int cURL error number (if any) */
41 + /**
42 + * @var int cURL error number (if any)
43 + */
29 44 public $errno = 0;
30 - /** @var \Exception Exception during on_headers (if any) */
45 + /**
46 + * @var \Throwable|null Exception during on_headers (if any)
47 + */
31 48 public $onHeadersException;
32 49 /**
50 + * @var \Exception|null Exception during createResponse (if any)
51 + */
52 + public $createResponseException;
53 + /**
33 54 * Attach a response to the easy handle based on the received headers.
34 55 *
35 - * @throws \RuntimeException if no headers have been received.
56 + * @throws \RuntimeException if no headers have been received or the first
57 + * header line is invalid.
36 58 */
37 - public function createResponse()
59 + public function createResponse() : void
38 60 {
39 - if (empty($this->headers)) {
40 - throw new \RuntimeException('No headers have been received');
41 - }
42 - // HTTP-version SP status-code SP reason-phrase
43 - $startLine = \explode(' ', \array_shift($this->headers), 3);
44 - $headers = \Dudlewebs\WPMCS\s3\GuzzleHttp\headers_from_lines($this->headers);
45 - $normalizedKeys = \Dudlewebs\WPMCS\s3\GuzzleHttp\normalize_header_keys($headers);
61 + [$ver, $status, $reason, $headers] = HeaderProcessor::parseHeaders($this->headers);
62 + $normalizedKeys = Utils::normalizeHeaderKeys($headers);
46 63 if (!empty($this->options['decode_content']) && isset($normalizedKeys['content-encoding'])) {
47 64 $headers['x-encoded-content-encoding'] = $headers[$normalizedKeys['content-encoding']];
48 65 unset($headers[$normalizedKeys['content-encoding']]);
49 66 if (isset($normalizedKeys['content-length'])) {
@@ -56,10 +73,17 @@
56 73 }
57 74 }
58 75 }
59 76 // Attach a response to the easy handle with the parsed headers.
60 - $this->response = new Response($startLine[1], $headers, $this->sink, \substr($startLine[0], 5), isset($startLine[2]) ? (string) $startLine[2] : null);
77 + $this->response = new Response($status, $headers, $this->sink, $ver, $reason);
61 78 }
79 + /**
80 + * @param string $name
81 + *
82 + * @return void
83 + *
84 + * @throws \BadMethodCallException
85 + */
62 86 public function __get($name)
63 87 {
64 88 $msg = $name === 'handle' ? 'The EasyHandle has been released' : 'Invalid property: ' . $name;
65 89 throw new \BadMethodCallException($msg);