PluginProbe
Gmail SMTP / trunk
Gmail SMTP vtrunk
1.2.3.21 1.2.3.20 trunk 1.0.5 1.0.6 1.0.7 1.0.8 1.0.9 1.1.0 1.1.1 1.1.2 1.1.9 1.2.0 1.2.3.14 1.2.3.15 1.2.3.16 1.2.3.18 1.2.3.5
gmail-smtp / google-api-php-client / vendor / guzzlehttp / guzzle / src / Handler / EasyHandle.php

EasyHandle.php in Gmail SMTP trunk, at google-api-php-client/vendor/guzzlehttp/guzzle/src/Handler/EasyHandle.php

120 lines 3.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
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 string|null Effective CURLOPT_PROXY value the handle was created with (if any)
55 */
56 public $effectiveProxy;
57
58 /**
59 * @var \Throwable|null Exception during on_headers (if any)
60 */
61 public $onHeadersException;
62
63 /**
64 * @var \Throwable|null Exception during createResponse (if any)
65 */
66 public $createResponseException;
67
68 /**
69 * Attach a response to the easy handle based on the received headers.
70 *
71 * @throws \RuntimeException if no headers have been received or the first
72 * header line is invalid.
73 */
74 public function createResponse(): void
75 {
76 $this->response = null;
77
78 [$ver, $status, $reason, $headers] = HeaderProcessor::parseHeaders($this->headers);
79
80 $normalizedKeys = Utils::normalizeHeaderKeys($headers);
81
82 if (isset($this->options['decode_content']) && $this->options['decode_content'] !== false && isset($normalizedKeys['content-encoding'])) {
83 $headers['x-encoded-content-encoding'] = $headers[$normalizedKeys['content-encoding']];
84 unset($headers[$normalizedKeys['content-encoding']]);
85 if (isset($normalizedKeys['content-length'])) {
86 $headers['x-encoded-content-length'] = $headers[$normalizedKeys['content-length']];
87
88 $bodyLength = (int) $this->sink->getSize();
89 if ($bodyLength) {
90 $headers[$normalizedKeys['content-length']] = [(string) $bodyLength];
91 } else {
92 unset($headers[$normalizedKeys['content-length']]);
93 }
94 }
95 }
96
97 // Attach a response to the easy handle with the parsed headers.
98 $this->response = new Response(
99 $status,
100 $headers,
101 $this->sink,
102 $ver,
103 $reason
104 );
105 }
106
107 /**
108 * @param string $name
109 *
110 * @return void
111 *
112 * @throws \BadMethodCallException
113 */
114 public function __get($name)
115 {
116 $msg = $name === 'handle' ? 'The EasyHandle has been released' : 'Invalid property: '.$name;
117 throw new \BadMethodCallException($msg);
118 }
119 }
120