1 | <?php |
||
16 | trait HttpHeadersTrait |
||
17 | { |
||
18 | |||
19 | /** |
||
20 | * Headers |
||
21 | * |
||
22 | * @var array |
||
23 | */ |
||
24 | private $headers; |
||
25 | |||
26 | /** |
||
27 | * The response status code |
||
28 | * |
||
29 | * @var int |
||
30 | */ |
||
31 | private $responseCode; |
||
32 | |||
33 | /** |
||
34 | * |
||
35 | * {@inheritdoc} |
||
36 | * @see \Generics\Streams\HttpStream::setHeader() |
||
37 | * @return HttpClient |
||
38 | */ |
||
39 | 22 | public function setHeader($headerName, $headerValue) |
|
43 | |||
44 | /** |
||
45 | * Reset the headers |
||
46 | */ |
||
47 | 25 | public function resetHeaders() |
|
51 | |||
52 | /** |
||
53 | * |
||
54 | * {@inheritdoc} |
||
55 | * @see \Generics\Streams\HttpStream::getHeaders() |
||
56 | */ |
||
57 | 22 | public function getHeaders(): array |
|
61 | |||
62 | /** |
||
63 | * Retrieve the response status code |
||
64 | * |
||
65 | * @return int |
||
66 | */ |
||
67 | 16 | public function getResponseCode(): int |
|
71 | |||
72 | /** |
||
73 | * Adjust the headers by injecting default values for missing keys. |
||
74 | */ |
||
75 | 22 | private function adjustHeaders($requestType) |
|
102 | |||
103 | /** |
||
104 | * Depending on request type the connection header is either |
||
105 | * set to keep-alive or close |
||
106 | * |
||
107 | * @param string $requestType |
||
108 | */ |
||
109 | 18 | private function adjustConnectionHeader($requestType) |
|
117 | |||
118 | /** |
||
119 | * Try to parse line as header and add the results to local header list |
||
120 | * |
||
121 | * @param string $line |
||
122 | */ |
||
123 | 18 | private function addParsedHeader($line) |
|
133 | |||
134 | /** |
||
135 | * Adjust number of bytes to read according content length header |
||
136 | * |
||
137 | * @param int $numBytes |
||
138 | * @return int |
||
139 | */ |
||
140 | 18 | private function adjustNumbytes($numBytes): int |
|
149 | |||
150 | /** |
||
151 | * Retrieve content type from headers |
||
152 | * |
||
153 | * @return string |
||
154 | */ |
||
155 | 14 | private function getContentEncoding(): string |
|
159 | |||
160 | /** |
||
161 | * Retrieve an given header |
||
162 | * |
||
163 | * @param string $name |
||
164 | * @return string |
||
165 | */ |
||
166 | 18 | private function getHeader(string $name): string |
|
176 | } |
||
177 |