← All changes
|
vendor_prefixed/guzzlehttp/guzzle/src/Handler/EasyHandle.php
+0
-67
18.2
→
trunk
View file →
| @@ -1,67 +1,0 @@ | ||
| 1 | -<?php | |
| 2 | - | |
| 3 | -namespace YoastSEO_Vendor\GuzzleHttp\Handler; | |
| 4 | - | |
| 5 | -use YoastSEO_Vendor\GuzzleHttp\Psr7\Response; | |
| 6 | -use YoastSEO_Vendor\Psr\Http\Message\RequestInterface; | |
| 7 | -use YoastSEO_Vendor\Psr\Http\Message\ResponseInterface; | |
| 8 | -use YoastSEO_Vendor\Psr\Http\Message\StreamInterface; | |
| 9 | -/** | |
| 10 | - * Represents a cURL easy handle and the data it populates. | |
| 11 | - * | |
| 12 | - * @internal | |
| 13 | - */ | |
| 14 | -final class EasyHandle | |
| 15 | -{ | |
| 16 | - /** @var resource cURL resource */ | |
| 17 | - public $handle; | |
| 18 | - /** @var StreamInterface Where data is being written */ | |
| 19 | - public $sink; | |
| 20 | - /** @var array Received HTTP headers so far */ | |
| 21 | - public $headers = []; | |
| 22 | - /** @var ResponseInterface Received response (if any) */ | |
| 23 | - public $response; | |
| 24 | - /** @var RequestInterface Request being sent */ | |
| 25 | - public $request; | |
| 26 | - /** @var array Request options */ | |
| 27 | - public $options = []; | |
| 28 | - /** @var int cURL error number (if any) */ | |
| 29 | - public $errno = 0; | |
| 30 | - /** @var \Exception Exception during on_headers (if any) */ | |
| 31 | - public $onHeadersException; | |
| 32 | - /** | |
| 33 | - * Attach a response to the easy handle based on the received headers. | |
| 34 | - * | |
| 35 | - * @throws \RuntimeException if no headers have been received. | |
| 36 | - */ | |
| 37 | - public function createResponse() | |
| 38 | - { | |
| 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 = \YoastSEO_Vendor\GuzzleHttp\headers_from_lines($this->headers); | |
| 45 | - $normalizedKeys = \YoastSEO_Vendor\GuzzleHttp\normalize_header_keys($headers); | |
| 46 | - if (!empty($this->options['decode_content']) && isset($normalizedKeys['content-encoding'])) { | |
| 47 | - $headers['x-encoded-content-encoding'] = $headers[$normalizedKeys['content-encoding']]; | |
| 48 | - unset($headers[$normalizedKeys['content-encoding']]); | |
| 49 | - if (isset($normalizedKeys['content-length'])) { | |
| 50 | - $headers['x-encoded-content-length'] = $headers[$normalizedKeys['content-length']]; | |
| 51 | - $bodyLength = (int) $this->sink->getSize(); | |
| 52 | - if ($bodyLength) { | |
| 53 | - $headers[$normalizedKeys['content-length']] = $bodyLength; | |
| 54 | - } else { | |
| 55 | - unset($headers[$normalizedKeys['content-length']]); | |
| 56 | - } | |
| 57 | - } | |
| 58 | - } | |
| 59 | - // Attach a response to the easy handle with the parsed headers. | |
| 60 | - $this->response = new \YoastSEO_Vendor\GuzzleHttp\Psr7\Response($startLine[1], $headers, $this->sink, \substr($startLine[0], 5), isset($startLine[2]) ? (string) $startLine[2] : null); | |
| 61 | - } | |
| 62 | - public function __get($name) | |
| 63 | - { | |
| 64 | - $msg = $name === 'handle' ? 'The EasyHandle has been released' : 'Invalid property: ' . $name; | |
| 65 | - throw new \BadMethodCallException($msg); | |
| 66 | - } | |
| 67 | -} | |