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