diff --git a/HttpServer/Http/HttpHeaders.php b/HttpServer/Http/HttpHeaders.php index ead781f0..b0fac482 100644 --- a/HttpServer/Http/HttpHeaders.php +++ b/HttpServer/Http/HttpHeaders.php @@ -16,88 +16,88 @@ namespace HttpServer\Http; trait HttpHeaders { - private array $_headers = []; + private array $_headers = []; - /** - * @param array $headers - */ - public function setHeaders(array $headers): void - { - $this->_headers = $headers; - } + /** + * @param array $headers + */ + public function setHeaders(array $headers): void + { + $this->_headers = $headers; + } - /** - * @return array - */ - public function toArray(): array - { - return $this->_headers; - } + /** + * @return array + */ + public function toArray(): array + { + return $this->_headers; + } - /** - * @param $name - * @return mixed|null - */ - public function getHeader($name): mixed - { - return $this->_headers[$name]; - } + /** + * @param $name + * @return mixed|null + */ + public function getHeader($name, $default = null): mixed + { + return $this->_headers[$name] ?? $default; + } - /** - * @return string - */ - public function getContentType(): string - { + /** + * @return string + */ + public function getContentType(): string + { return $this->_headers['content-type'] ?? ''; - } + } - /** - * @return string|null - */ - public function getRequestUri(): ?string - { + /** + * @return string|null + */ + public function getRequestUri(): ?string + { return $this->_headers['request_uri']; - } + } - /** - * @return string|null - */ - public function getRequestMethod(): ?string - { + /** + * @return string|null + */ + public function getRequestMethod(): ?string + { return $this->_headers['request_method']; - } + } - /** - * @return mixed - */ - public function getAgent(): mixed - { + /** + * @return mixed + */ + public function getAgent(): mixed + { return $this->_headers['user-agent']; - } + } - /** - * @param $name - * @return bool - */ - public function exists($name): bool - { - return $this->_headers[$name] ?? null === null; - } + /** + * @param $name + * @return bool + */ + public function exists($name): bool + { + return $this->_headers[$name] ?? null === null; + } - /** - * @return array - */ - public function getHeaders(): array - { - return $this->_headers; - } + /** + * @return array + */ + public function getHeaders(): array + { + return $this->_headers; + } }