| 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 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
final class EasyHandle |
| 17 |
{ |
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
public $handle; |
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
public $sink; |
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
public $headers = []; |
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
public $response; |
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
public $request; |
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
public $options = []; |
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
public $errno = 0; |
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
public $onHeadersException; |
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
public $createResponseException; |
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
public function createResponse(): void |
| 70 |
{ |
| 71 |
$this->response = null; |
| 72 |
|
| 73 |
[$ver, $status, $reason, $headers] = HeaderProcessor::parseHeaders($this->headers); |
| 74 |
|
| 75 |
$normalizedKeys = Utils::normalizeHeaderKeys($headers); |
| 76 |
|
| 77 |
if (!empty($this->options['decode_content']) && isset($normalizedKeys['content-encoding'])) { |
| 78 |
$headers['x-encoded-content-encoding'] = $headers[$normalizedKeys['content-encoding']]; |
| 79 |
unset($headers[$normalizedKeys['content-encoding']]); |
| 80 |
if (isset($normalizedKeys['content-length'])) { |
| 81 |
$headers['x-encoded-content-length'] = $headers[$normalizedKeys['content-length']]; |
| 82 |
|
| 83 |
$bodyLength = (int) $this->sink->getSize(); |
| 84 |
if ($bodyLength) { |
| 85 |
$headers[$normalizedKeys['content-length']] = [(string) $bodyLength]; |
| 86 |
} else { |
| 87 |
unset($headers[$normalizedKeys['content-length']]); |
| 88 |
} |
| 89 |
} |
| 90 |
} |
| 91 |
|
| 92 |
|
| 93 |
$this->response = new Response( |
| 94 |
$status, |
| 95 |
$headers, |
| 96 |
$this->sink, |
| 97 |
$ver, |
| 98 |
$reason |
| 99 |
); |
| 100 |
} |
| 101 |
|
| 102 |
|
| 103 |
|
| 104 |
|
| 105 |
|
| 106 |
|
| 107 |
|
| 108 |
|
| 109 |
public function __get($name) |
| 110 |
{ |
| 111 |
$msg = $name === 'handle' ? 'The EasyHandle has been released' : 'Invalid property: '.$name; |
| 112 |
throw new \BadMethodCallException($msg); |
| 113 |
} |
| 114 |
} |