82 lines
2.1 KiB
PHP
82 lines
2.1 KiB
PHP
<?php
|
|
// HttpMessage.php
|
|
// Created: 2022-02-08
|
|
// Updated: 2024-07-31
|
|
|
|
namespace Index\Http;
|
|
|
|
use Index\IO\Stream;
|
|
use Index\Http\Content\IHttpContent;
|
|
use Index\Http\Content\BencodedContent;
|
|
use Index\Http\Content\FormContent;
|
|
use Index\Http\Content\JsonContent;
|
|
use Index\Http\Content\StreamContent;
|
|
use Index\Http\Content\StringContent;
|
|
|
|
abstract class HttpMessage {
|
|
private string $version;
|
|
private HttpHeaders $headers;
|
|
private ?IHttpContent $content;
|
|
|
|
public function __construct(string $version, HttpHeaders $headers, ?IHttpContent $content) {
|
|
$this->version = $version;
|
|
$this->headers = $headers;
|
|
$this->content = $content;
|
|
}
|
|
|
|
public function getHttpVersion(): string {
|
|
return $this->version;
|
|
}
|
|
|
|
public function getHeaders(): array {
|
|
return $this->headers->getHeaders();
|
|
}
|
|
|
|
public function hasHeader(string $name): bool {
|
|
return $this->headers->hasHeader($name);
|
|
}
|
|
|
|
public function getHeader(string $name): HttpHeader {
|
|
return $this->headers->getHeader($name);
|
|
}
|
|
|
|
public function getHeaderLine(string $name): string {
|
|
return $this->headers->getHeaderLine($name);
|
|
}
|
|
|
|
public function getHeaderLines(string $name): array {
|
|
return $this->headers->getHeaderLines($name);
|
|
}
|
|
|
|
public function getHeaderFirstLine(string $name): string {
|
|
return $this->headers->getHeaderFirstLine($name);
|
|
}
|
|
|
|
public function hasContent(): bool {
|
|
return $this->content !== null;
|
|
}
|
|
|
|
public function getContent(): ?IHttpContent {
|
|
return $this->content;
|
|
}
|
|
|
|
public function isJsonContent(): bool {
|
|
return $this->content instanceof JsonContent;
|
|
}
|
|
|
|
public function isFormContent(): bool {
|
|
return $this->content instanceof FormContent;
|
|
}
|
|
|
|
public function isStreamContent(): bool {
|
|
return $this->content instanceof StreamContent;
|
|
}
|
|
|
|
public function isStringContent(): bool {
|
|
return $this->content instanceof StringContent;
|
|
}
|
|
|
|
public function isBencodedContent(): bool {
|
|
return $this->content instanceof BencodedContent;
|
|
}
|
|
}
|