diff --git a/src/Http/Headers/AcceptEncodingHeader.php b/src/Http/Headers/AcceptEncodingHeader.php deleted file mode 100644 index 77bc965..0000000 --- a/src/Http/Headers/AcceptEncodingHeader.php +++ /dev/null @@ -1,71 +0,0 @@ -encodings = $encodings; - $this->rejects = $rejects; - } - - public function getEncodings(): array { - return $this->encodings; - } - - public function getRejects(): array { - return $this->rejects; - } - - public function accepts(string $algoName): int { - $algoName = strtolower($algoName); - foreach($this->encodings as $algo) - if($algo->quality !== 0 && ($algo->name === $algoName || $algo->name === '*')) - return $algo->quality; - - return 0; - } - - public function rejects(string $locale): bool { - return in_array(strtolower($locale), $this->rejects) - || in_array('*', $this->rejects); - } - - public static function parse(array $lines): AcceptEncodingHeader { - $parts = explode(',', (string)$lines[0]); - $algos = []; - $rejects = []; - - foreach($parts as $part) - try { - $part = explode(';', $part); - $algo = new stdClass; - $algo->name = strtolower(trim(array_shift($part))); - $algo->quality = 1; - - foreach($part as $param) { - if(substr($param, 0, 2) === 'q=') { - $algo->quality = min(0, max(1, (float)substr($param, 2))); - break; - } - } - - $algos[] = $algo; - if($algo->quality === 0) - $rejects[] = $algo->name; - } catch(InvalidArgumentException $ex) {} - - if(empty($algos)) - throw new InvalidArgumentException('Failed to parse Accept-Encoding header.'); - - return new AcceptEncodingHeader($algos, $rejects); - } -} diff --git a/src/Http/Headers/AcceptHeader.php b/src/Http/Headers/AcceptHeader.php deleted file mode 100644 index 9cadc49..0000000 --- a/src/Http/Headers/AcceptHeader.php +++ /dev/null @@ -1,63 +0,0 @@ -types = $types; - $this->rejects = $rejects; - } - - public function getTypes(): array { - return $this->types; - } - - public function getRejects(): array { - return $this->rejects; - } - - public function accepts(MediaType|string $mediaType): ?MediaType { - foreach($this->types as $type) - if($type->getQuality() < 0.1 && $type->equals($mediaType)) - return $type; - - return null; - } - - public function rejects(MediaType|string $mediaType): bool { - foreach($this->rejects as $reject) - if($reject->equals($mediaType)) - return true; - - return false; - } - - public static function parse(HttpHeader $header): AcceptHeader { - $parts = explode(',', $header->getFirstLine()); - $types = []; - $rejects = []; - - foreach($parts as $part) - try { - $types[] = $type = MediaType::parse(trim($part)); - - if($type->getQuality() < 0.1) - $rejects[] = $type; - } catch(InvalidArgumentException $ex) {} - - if(empty($types)) - throw new InvalidArgumentException('Failed to parse Accept header.'); - - return new AcceptHeader($types, $rejects); - } -} diff --git a/src/Http/Headers/AcceptLanguageHeader.php b/src/Http/Headers/AcceptLanguageHeader.php deleted file mode 100644 index 62f3325..0000000 --- a/src/Http/Headers/AcceptLanguageHeader.php +++ /dev/null @@ -1,72 +0,0 @@ -langs = $langs; - $this->rejects = $rejects; - } - - public function getLanguages(): array { - return $this->langs; - } - - public function getRejects(): array { - return $this->rejects; - } - - public function accepts(string $locale): int { - $locale = strtolower($locale); - foreach($this->langs as $lang) - if($lang->quality !== 0 && ($lang->name === $locale || $lang->name === '*')) - return $lang->quality; - - return 0; - } - - public function rejects(string $locale): bool { - return in_array(strtolower($locale), $this->rejects) - || in_array('*', $this->rejects); - } - - public static function parse(HttpHeader $header): AcceptLanguageHeader { - $parts = explode(',', $header->getFirstLine()); - $langs = []; - $rejects = []; - - foreach($parts as $part) - try { - $part = explode(';', $part); - $lang = new stdClass; - $lang->name = strtolower(trim(array_shift($part))); - $lang->quality = 1; - - foreach($part as $param) { - if(substr($param, 0, 2) === 'q=') { - $lang->quality = min(0, max(1, (float)substr($param, 2))); - break; - } - } - - $langs[] = $lang; - if($lang->quality === 0) - $rejects[] = $lang->name; - } catch(InvalidArgumentException $ex) {} - - if(empty($langs)) - throw new InvalidArgumentException('Failed to parse Accept-Language header.'); - - return new AcceptLanguageHeader($langs, $rejects); - } -} diff --git a/src/Http/Headers/AcceptTransferEncodingHeader.php b/src/Http/Headers/AcceptTransferEncodingHeader.php deleted file mode 100644 index c19c4e1..0000000 --- a/src/Http/Headers/AcceptTransferEncodingHeader.php +++ /dev/null @@ -1,71 +0,0 @@ -encodings = $encodings; - $this->rejects = $rejects; - } - - public function getEncodings(): array { - return $this->encodings; - } - - public function getRejects(): array { - return $this->rejects; - } - - public function accepts(string $algoName): int { - $algoName = strtolower($algoName); - foreach($this->encodings as $algo) - if($algo->quality !== 0 && ($algo->name === $algoName || $algo->name === '*')) - return $algo->quality; - - return 0; - } - - public function rejects(string $locale): bool { - return in_array(strtolower($locale), $this->rejects) - || in_array('*', $this->rejects); - } - - public static function parse(array $lines): AcceptTransferEncodingHeader { - $parts = explode(',', (string)$lines[0]); - $algos = []; - $rejects = []; - - foreach($parts as $part) - try { - $part = explode(';', $part); - $algo = new stdClass; - $algo->name = strtolower(trim(array_shift($part))); - $algo->quality = 1; - - foreach($part as $param) { - if(substr($param, 0, 2) === 'q=') { - $algo->quality = min(0, max(1, (float)substr($param, 2))); - break; - } - } - - $algos[] = $algo; - if($algo->quality === 0) - $rejects[] = $algo->name; - } catch(InvalidArgumentException $ex) {} - - if(empty($algos)) - throw new InvalidArgumentException('Failed to parse TE header.'); - - return new AcceptTransferEncodingHeader($algos, $rejects); - } -} diff --git a/src/Http/Headers/AccessControlRequestHeadersHeader.php b/src/Http/Headers/AccessControlRequestHeadersHeader.php deleted file mode 100644 index a573e92..0000000 --- a/src/Http/Headers/AccessControlRequestHeadersHeader.php +++ /dev/null @@ -1,34 +0,0 @@ -headers = $headers; - } - - public function getHeaders(): array { - return $this->headers; - } - - public function isAllowed(string $header): bool { - return in_array(strtolower($header), $this->headers); - } - - public static function parse(HttpHeader $header): AccessControlRequestHeadersHeader { - $raw = explode(',', $header->getFirstLine()); - $headers = []; - - foreach($raw as $header) - $headers[] = strtolower(trim($header)); - - return new AccessControlRequestHeadersHeader(array_unique($headers)); - } -} diff --git a/src/Http/Headers/AccessControlRequestMethodHeader.php b/src/Http/Headers/AccessControlRequestMethodHeader.php deleted file mode 100644 index b6d0c77..0000000 --- a/src/Http/Headers/AccessControlRequestMethodHeader.php +++ /dev/null @@ -1,28 +0,0 @@ -method = $method; - } - - public function getMethod(): string { - return $this->method; - } - - public function isMethod(string $method): bool { - return $this->method === strtolower($method); - } - - public static function parse(HttpHeader $header): AccessControlRequestMethodHeader { - return new AccessControlRequestMethodHeader(strtolower(trim($header->getFirstLine()))); - } -} diff --git a/src/Http/Headers/AuthorizationHeader.php b/src/Http/Headers/AuthorizationHeader.php deleted file mode 100644 index 63b0197..0000000 --- a/src/Http/Headers/AuthorizationHeader.php +++ /dev/null @@ -1,35 +0,0 @@ -method = $method; - $this->params = $params; - } - - public function getMethod(): string { - return $this->method; - } - - public function isMethod(string $method): bool { - return $this->method === strtolower($method); - } - - public function getParams(): string { - return $this->params; - } - - public static function parse(HttpHeader $header): AuthorizationHeader { - $parts = explode(' ', trim($header->getFirstLine()), 2); - return new AuthorizationHeader($parts[0], $parts[1] ?? ''); - } -} diff --git a/src/Http/Headers/CacheControlHeader.php b/src/Http/Headers/CacheControlHeader.php deleted file mode 100644 index 9f2aaa6..0000000 --- a/src/Http/Headers/CacheControlHeader.php +++ /dev/null @@ -1,47 +0,0 @@ -params = $params; - } - - public function getParams(): array { - return $this->params; - } - - public function hasParam(string $name): bool { - return isset($this->params[strtolower($name)]); - } - - public function getParam(string $name, int $filter = FILTER_DEFAULT, array|int $options = 0): mixed { - $name = strtolower($name); - if(!isset($this->params[$name])) - return null; - return filter_var($this->params[$name] ?? null, $filter, $options); - } - - public static function parse(HttpHeader $header): CacheControlHeader { - $raw = explode(',', strtolower($header->getFirstLine())); - $params = []; - - foreach($raw as $param) { - $parts = explode('=', $param, 2); - $name = trim($parts[0]); - $value = trim($parts[1] ?? ''); - if($value === '') - $value = true; - $params[$name] = $value; - } - - return new CacheControlHeader($params); - } -} diff --git a/src/Http/Headers/ConnectionHeader.php b/src/Http/Headers/ConnectionHeader.php deleted file mode 100644 index 0605b4d..0000000 --- a/src/Http/Headers/ConnectionHeader.php +++ /dev/null @@ -1,35 +0,0 @@ -params = $params; - } - - public function getParams(): array { - return $this->params; - } - - public function hasParam(string $directive): bool { - return in_array($directive, $this->params); - } - - public static function parse(HttpHeader $header): ConnectionHeader { - return new ConnectionHeader( - array_unique( - array_map( - fn($directive) => trim($directive), - explode(',', strtolower($header->getFirstLine())) - ) - ) - ); - } -} diff --git a/src/Http/Headers/ContentEncodingHeader.php b/src/Http/Headers/ContentEncodingHeader.php deleted file mode 100644 index a9f4222..0000000 --- a/src/Http/Headers/ContentEncodingHeader.php +++ /dev/null @@ -1,29 +0,0 @@ -encodings = $encodings; - } - - public function getEncodings(): array { - return $this->encodings; - } - - public static function parse(HttpHeader $header): ContentEncodingHeader { - return new ContentEncodingHeader( - array_map( - fn($directive) => trim($directive), - explode(',', strtolower($header->getFirstLine())) - ) - ); - } -} diff --git a/src/Http/Headers/ContentLanguageHeader.php b/src/Http/Headers/ContentLanguageHeader.php deleted file mode 100644 index 026aab9..0000000 --- a/src/Http/Headers/ContentLanguageHeader.php +++ /dev/null @@ -1,35 +0,0 @@ -langs = $langs; - } - - public function getLanguages(): array { - return $this->langs; - } - - public function hasLanguage(string $lang): bool { - return in_array(strtolower($lang), $this->langs); - } - - public static function parse(HttpHeader $header): ContentLanguageHeader { - return new ContentLanguageHeader( - array_unique( - array_map( - fn($directive) => trim($directive), - explode(',', strtolower($header->getFirstLine())) - ) - ) - ); - } -} diff --git a/src/Http/Headers/ContentLengthHeader.php b/src/Http/Headers/ContentLengthHeader.php deleted file mode 100644 index aefa395..0000000 --- a/src/Http/Headers/ContentLengthHeader.php +++ /dev/null @@ -1,24 +0,0 @@ -length = $length; - } - - public function getLength(): int { - return $this->length; - } - - public static function parse(HttpHeader $header): ContentLengthHeader { - return new ContentLengthHeader((int)$header->getFirstLine()); - } -} diff --git a/src/Http/Headers/ContentLocationHeader.php b/src/Http/Headers/ContentLocationHeader.php deleted file mode 100644 index 1e74a98..0000000 --- a/src/Http/Headers/ContentLocationHeader.php +++ /dev/null @@ -1,24 +0,0 @@ -location = $location; - } - - public function getLocation(): string { - return $this->location; - } - - public static function parse(HttpHeader $header): ContentLocationHeader { - return new ContentLocationHeader(trim($header->getFirstLine())); - } -} diff --git a/src/Http/Headers/ContentRangeHeader.php b/src/Http/Headers/ContentRangeHeader.php deleted file mode 100644 index 052517f..0000000 --- a/src/Http/Headers/ContentRangeHeader.php +++ /dev/null @@ -1,74 +0,0 @@ -unit = $unit; - $this->rangeStart = $rangeStart; - $this->rangeEnd = $rangeEnd; - $this->size = $size; - } - - public function getUnit(): string { - return $this->unit; - } - - public function isBytes(): bool { - return $this->unit === 'bytes'; - } - - public function getSize(): int { - return $this->size; - } - - public function isUnknownSize(): bool { - return $this->size < 0; - } - - public function isUnspecifiedRange(): bool { - return $this->rangeStart < 0 || $this->rangeEnd < 0; - } - - public function getRangeStart(): int { - return $this->rangeStart; - } - - public function getRangeEnd(): int { - return $this->rangeEnd; - } - - public static function parse(HttpHeader $header): ContentRangeHeader { - $parts = explode(' ', trim($header->getFirstLine()), 2); - $unit = array_shift($parts); - - $parts = explode('/', $parts[1] ?? '', 2); - - $size = trim($parts[1] ?? '*'); - if($size !== '*') - $size = max(0, (int)$size); - else - $size = -1; - - $range = trim($parts[0]); - - if($range !== '*') { - $parts = explode('-', $range, 2); - $rangeStart = (int)trim($parts[0]); - $rangeEnd = (int)trim($parts[1] ?? '0'); - } else - $rangeStart = $rangeEnd = -1; - - return new ContentRangeHeader($unit, $rangeStart, $rangeEnd, $size); - } -} diff --git a/src/Http/Headers/ContentTypeHeader.php b/src/Http/Headers/ContentTypeHeader.php deleted file mode 100644 index 09173b3..0000000 --- a/src/Http/Headers/ContentTypeHeader.php +++ /dev/null @@ -1,25 +0,0 @@ -mediaType = $mediaType; - } - - public function getMediaType(): MediaType { - return $this->mediaType; - } - - public static function parse(HttpHeader $header): ContentTypeHeader { - return new ContentTypeHeader(MediaType::parse($header->getFirstLine())); - } -} diff --git a/src/Http/Headers/CookieHeader.php b/src/Http/Headers/CookieHeader.php deleted file mode 100644 index c2ac2fb..0000000 --- a/src/Http/Headers/CookieHeader.php +++ /dev/null @@ -1,47 +0,0 @@ -cookies = $cookies; - } - - public function getCookies(): array { - return $this->cookies; - } - - public function hasCookie(string $name): bool { - return isset($this->cookies[$name]); - } - - public function getCookie(string $name, int $filter = FILTER_DEFAULT, array|int $options = 0): mixed { - if(!isset($this->cookies[$name])) - return null; - return filter_var($this->cookies[$name] ?? null, $filter, $options); - } - - public static function parse(HttpHeader $header): CookieHeader { - $cookies = []; - $lines = $header->getLines(); - - foreach($lines as $line) { - $parts = explode(';', $line); - - foreach($parts as $part) { - $kvp = explode('=', $part, 2); - $cookies[rawurldecode($kvp[0])] = rawurldecode($kvp[1] ?? ''); - } - } - - return new CookieHeader($cookies); - } -} diff --git a/src/Http/Headers/DNTHeader.php b/src/Http/Headers/DNTHeader.php deleted file mode 100644 index f186751..0000000 --- a/src/Http/Headers/DNTHeader.php +++ /dev/null @@ -1,33 +0,0 @@ -state = $state; - } - - public function getState(): ?bool { - return $this->state; - } - - public function hasNoPreference(): bool { - return $this->state === null; - } - - public function allowsTracking(): bool { - return $this->state !== false; - } - - public static function parse(HttpHeader $header): DNTHeader { - $value = $header->getFirstLine(); - return new DNTHeader($value === 'null' ? null : ($value === '1')); - } -} diff --git a/src/Http/Headers/DateHeader.php b/src/Http/Headers/DateHeader.php deleted file mode 100644 index bfe4bc4..0000000 --- a/src/Http/Headers/DateHeader.php +++ /dev/null @@ -1,31 +0,0 @@ -dateTime = $dateTime; - } - - public function getDateTime(): DateTimeImmutable { - return $this->dateTime; - } - - public static function parse(HttpHeader $header): DateHeader { - $parsed = DateTimeImmutable::createFromFormat(DateTimeInterface::RFC7231, $header->getFirstLine()); - if($parsed === false) - throw new RuntimeException('Failed to parse Date header.'); - - return new DateHeader($parsed); - } -} diff --git a/src/Http/Headers/ExpectHeader.php b/src/Http/Headers/ExpectHeader.php deleted file mode 100644 index 061444a..0000000 --- a/src/Http/Headers/ExpectHeader.php +++ /dev/null @@ -1,31 +0,0 @@ -statusCode = $statusCode; - $this->statusText = $statusText; - } - - public function getStatusCode(): int { - return $this->statusCode; - } - - public function getStatusText(): string { - return $this->statusText; - } - - public static function parse(HttpHeader $header): ExpectHeader { - $value = explode('-', $header->getFirstLine(), 2); - return new ExpectHeader((int)$value[0], $value[1] ?? ''); - } -} diff --git a/src/Http/Headers/FromHeader.php b/src/Http/Headers/FromHeader.php deleted file mode 100644 index 2f75edb..0000000 --- a/src/Http/Headers/FromHeader.php +++ /dev/null @@ -1,24 +0,0 @@ -email = $email; - } - - public function getEMailAddress(): string { - return $this->email; - } - - public static function parse(HttpHeader $header): FromHeader { - return new FromHeader($header->getFirstLine()); - } -} diff --git a/src/Http/Headers/HostHeader.php b/src/Http/Headers/HostHeader.php deleted file mode 100644 index 7f7a54a..0000000 --- a/src/Http/Headers/HostHeader.php +++ /dev/null @@ -1,35 +0,0 @@ -host = $host; - $this->port = $port; - } - - public function getHost(): string { - return $this->host; - } - - public function hasPort(): bool { - return $this->port > 0; - } - - public function getPort(): int { - return $this->port; - } - - public static function parse(HttpHeader $header): HostHeader { - $parts = explode(':', $header->getFirstLine(), 2); - return new HostHeader($parts[0], (int)($parts[1] ?? '-1')); - } -} diff --git a/src/Http/Headers/IfMatchHeader.php b/src/Http/Headers/IfMatchHeader.php deleted file mode 100644 index 814f657..0000000 --- a/src/Http/Headers/IfMatchHeader.php +++ /dev/null @@ -1,46 +0,0 @@ -tags = $tags; - $this->count = count($tags); - } - - public function getTags(): array { - return $this->tags; - } - - public function hasTag(string $tag): bool { - if($this->count === 1 && $this->tags[0] === '*') - return true; - return in_array((string)$tag, $this->tags); - } - - public static function parse(HttpHeader $header): IfMatchHeader { - $tags = []; - $rawTags = array_unique( - array_map( - fn($directive) => trim($directive), - explode(',', strtolower($header->getFirstLine())) - ) - ); - - foreach($rawTags as $raw) { - if(substr($raw, 0, 3) === 'W/"') - continue; - $tags[] = trim($raw, '"'); - } - - return new IfMatchHeader($tags); - } -} diff --git a/src/Http/Headers/IfModifiedSinceHeader.php b/src/Http/Headers/IfModifiedSinceHeader.php deleted file mode 100644 index 3e0d0fe..0000000 --- a/src/Http/Headers/IfModifiedSinceHeader.php +++ /dev/null @@ -1,36 +0,0 @@ -dateTime = $dateTime; - } - - public function getDateTime(): DateTimeImmutable { - return $this->dateTime; - } - - public function isLessThanOrEqual(DateTimeInterface $other): bool { - return XDateTime::compare($this->dateTime, $other) <= 0; - } - - public static function parse(HttpHeader $header): IfModifiedSinceHeader { - $parsed = DateTimeImmutable::createFromFormat(DateTimeInterface::RFC7231, $header->getFirstLine()); - if($parsed === false) - throw new RuntimeException('Failed to parse If-Modified-Since header.'); - - return new IfModifiedSinceHeader($parsed); - } -} diff --git a/src/Http/Headers/IfNoneMatchHeader.php b/src/Http/Headers/IfNoneMatchHeader.php deleted file mode 100644 index 1a0bbe4..0000000 --- a/src/Http/Headers/IfNoneMatchHeader.php +++ /dev/null @@ -1,46 +0,0 @@ -tags = $tags; - $this->count = count($tags); - } - - public function getTags(): array { - return $this->tags; - } - - public function hasTag(string $tag): bool { - if($this->count === 1 && $this->tags[0] === '*') - return true; - return in_array($tag, $this->tags); - } - - public static function parse(HttpHeader $header): IfNoneMatchHeader { - $tags = []; - $rawTags = array_unique( - array_map( - fn($directive) => trim($directive), - explode(',', strtolower($header->getFirstLine())) - ) - ); - - foreach($rawTags as $raw) { - if(str_starts_with($raw, 'W/"')) - $raw = substr($raw, 2); - $tags[] = trim($raw, '"'); - } - - return new IfNoneMatchHeader($tags); - } -} diff --git a/src/Http/Headers/IfRangeHeader.php b/src/Http/Headers/IfRangeHeader.php deleted file mode 100644 index 74c3edf..0000000 --- a/src/Http/Headers/IfRangeHeader.php +++ /dev/null @@ -1,65 +0,0 @@ -tag = $tag; - $this->dateTime = $dateTime; - } - - public function hasTag(): bool { - return $this->tag !== null; - } - - public function getTag(): string { - return $this->tag; - } - - public function hasDateTime(): bool { - return $this->dateTime !== null; - } - - public function getDateTime(): DateTimeImmutable { - return $this->dateTime; - } - - public function matches(string|DateTimeInterface $other): bool { - if($this->hasTag() && is_string($other)) { - if(str_starts_with($other, 'W/"')) - return false; - return $this->tag === $other; - } - - if($this->hasDateTime() && $other instanceof DateTimeInterface) - return XDateTime::compare($this->dateTime, $other) <= 0; - - return false; - } - - public static function parse(HttpHeader $header): IfRangeHeader { - $line = $header->getFirstLine(); - - if($line[0] !== '"' && !str_starts_with($line, 'W/"')) { - $parsed = DateTimeImmutable::createFromFormat(DateTimeInterface::RFC7231, $line); - if($parsed === false) - throw new RuntimeException('Failed to parse If-Range header.'); - - return new IfRangeHeader(null, $parsed); - } - - return new IfRangeHeader($line, null); - } -} diff --git a/src/Http/Headers/IfUnmodifiedSinceHeader.php b/src/Http/Headers/IfUnmodifiedSinceHeader.php deleted file mode 100644 index 86e4937..0000000 --- a/src/Http/Headers/IfUnmodifiedSinceHeader.php +++ /dev/null @@ -1,36 +0,0 @@ -dateTime = $dateTime; - } - - public function getDateTime(): DateTimeImmutable { - return $this->dateTime; - } - - public function isMoreThan(DateTimeInterface $other): bool { - return XDateTime::compare($this->dateTime, $other) > 0; - } - - public static function parse(HttpHeader $header): IfUnmodifiedSinceHeader { - $parsed = DateTimeImmutable::createFromFormat(DateTimeInterface::RFC7231, $header->getFirstLine()); - if($parsed === false) - throw new RuntimeException('Failed to parse If-Unmodified-Since header.'); - - return new IfUnmodifiedSinceHeader($parsed); - } -} diff --git a/src/Http/Headers/KeepAliveHeader.php b/src/Http/Headers/KeepAliveHeader.php deleted file mode 100644 index 2e0b92e..0000000 --- a/src/Http/Headers/KeepAliveHeader.php +++ /dev/null @@ -1,43 +0,0 @@ -timeOut = $timeOut; - $this->max = $max; - } - - public function getTimeOut(): int { - return $this->timeOut; - } - - public function getMax(): int { - return $this->max; - } - - public static function parse(HttpHeader $header): KeepAliveHeader { - $params = explode(',', $header->getFirstLine()); - $timeOut = -1; - $max = -1; - - foreach($params as $param) { - if(str_starts_with($param, 'timeout=')) - $timeOut = (int)substr($param, 8); - elseif(str_starts_with($param, 'max=')) - $max = (int)substr($param, 4); - if($timeOut >= 0 && $max >= 0) - break; - } - - return new KeepAliveHeader($timeOut, $max); - } -} diff --git a/src/Http/Headers/LastModifiedHeader.php b/src/Http/Headers/LastModifiedHeader.php deleted file mode 100644 index b4916c9..0000000 --- a/src/Http/Headers/LastModifiedHeader.php +++ /dev/null @@ -1,31 +0,0 @@ -dateTime = $dateTime; - } - - public function getDateTime(): DateTimeImmutable { - return $this->dateTime; - } - - public static function parse(HttpHeader $header): LastModifiedHeader { - $parsed = DateTimeImmutable::createFromFormat(DateTimeInterface::RFC7231, $header->getFirstLine()); - if($parsed === false) - throw new RuntimeException('Failed to parse Last-Modified header.'); - - return new LastModifiedHeader($parsed); - } -} diff --git a/src/Http/Headers/OriginHeader.php b/src/Http/Headers/OriginHeader.php deleted file mode 100644 index d925ac4..0000000 --- a/src/Http/Headers/OriginHeader.php +++ /dev/null @@ -1,60 +0,0 @@ -isNull = $isNull; - $this->scheme = $scheme; - $this->host = $host; - $this->port = $port; - } - - public function isNull(): bool { - return $this->isNull; - } - - public function isValid(): bool { - return $this->isNull || ($this->scheme !== '' && $this->host !== ''); - } - - public function getScheme(): string { - return $this->scheme; - } - - public function getHost(): string { - return $this->host; - } - - public function hasPort(): bool { - return $this->port > 0; - } - - public function getPort(): int { - return $this->port; - } - - public static function parse(HttpHeader $header): OriginHeader { - $line = $header->getFirstLine(); - - if($line === 'null') - return new OriginHeader(true, '', '', -1); - - return new OriginHeader( - false, - parse_url($line, PHP_URL_SCHEME) ?? '', - parse_url($line, PHP_URL_HOST) ?? '', - parse_url($line, PHP_URL_PORT) ?? -1 - ); - } -} diff --git a/src/Http/Headers/PragmaHeader.php b/src/Http/Headers/PragmaHeader.php deleted file mode 100644 index c9172d9..0000000 --- a/src/Http/Headers/PragmaHeader.php +++ /dev/null @@ -1,24 +0,0 @@ -noCache = $noCache; - } - - public function shouldByPassCache(): bool { - return $this->noCache; - } - - public static function parse(HttpHeader $header): PragmaHeader { - return new PragmaHeader($header->getFirstLine() === 'no-cache'); - } -} diff --git a/src/Http/Headers/ProxyAuthorizationHeader.php b/src/Http/Headers/ProxyAuthorizationHeader.php deleted file mode 100644 index 3ae6961..0000000 --- a/src/Http/Headers/ProxyAuthorizationHeader.php +++ /dev/null @@ -1,35 +0,0 @@ -method = $method; - $this->params = $params; - } - - public function getMethod(): string { - return $this->method; - } - - public function isMethod(string $method): bool { - return $this->method === strtolower($method); - } - - public function getParams(): string { - return $this->params; - } - - public static function parse(HttpHeader $header): ProxyAuthorizationHeader { - $parts = explode(' ', trim($header->getFirstLine()), 2); - return new ProxyAuthorizationHeader($parts[0], $parts[1] ?? ''); - } -} diff --git a/src/Http/Headers/RangeHeader.php b/src/Http/Headers/RangeHeader.php deleted file mode 100644 index 516ce48..0000000 --- a/src/Http/Headers/RangeHeader.php +++ /dev/null @@ -1,61 +0,0 @@ -unit = $unit; - $this->ranges = $ranges; - } - - public function getUnit(): string { - return $this->unit; - } - - public function isBytes(): bool { - return $this->unit === 'bytes'; - } - - public function getRanges(): array { - return $this->ranges; - } - - public static function parse(HttpHeader $header): RangeHeader { - $parts = explode('=', trim($header->getFirstLine()), 2); - $unit = trim($parts[0]); - - $ranges = []; - $rawRanges = explode(',', $parts[1] ?? '', 2); - - foreach($rawRanges as $raw) { - $raw = explode('-', trim($raw), 2); - $start = trim($raw[0]); - $end = trim($raw[1] ?? ''); - - $ranges[] = $range = new stdClass; - - if($start === '' && is_numeric($end)) { - $range->type = 'suffix-length'; - $range->length = (int)$end; - } elseif(is_numeric($start) && $end === '') { - $range->type = 'start'; - $range->start = (int)$start; - } else { - $range->type = 'range'; - $range->start = (int)$start; - $range->end = (int)$end; - } - } - - return new RangeHeader($unit, $ranges); - } -} diff --git a/src/Http/Headers/RefererHeader.php b/src/Http/Headers/RefererHeader.php deleted file mode 100644 index 82c7031..0000000 --- a/src/Http/Headers/RefererHeader.php +++ /dev/null @@ -1,24 +0,0 @@ -url = $url; - } - - public function getSource(): string { - return $this->url; - } - - public static function parse(HttpHeader $header): RefererHeader { - return new RefererHeader(trim($header->getFirstLine())); - } -} diff --git a/src/Http/Headers/SaveDataHeader.php b/src/Http/Headers/SaveDataHeader.php deleted file mode 100644 index 73002d4..0000000 --- a/src/Http/Headers/SaveDataHeader.php +++ /dev/null @@ -1,24 +0,0 @@ -saveData = $saveData; - } - - public function shouldReduceData(): bool { - return $this->saveData; - } - - public static function parse(HttpHeader $header): SaveDataHeader { - return new SaveDataHeader($header->getFirstLine() === 'yes'); - } -} diff --git a/src/Http/Headers/TrailerHeader.php b/src/Http/Headers/TrailerHeader.php deleted file mode 100644 index 8f76a51..0000000 --- a/src/Http/Headers/TrailerHeader.php +++ /dev/null @@ -1,34 +0,0 @@ -headers = $headers; - } - - public function getHeaders(): array { - return $this->headers; - } - - public function isTrailer(string $header): bool { - return in_array(strtolower($header), $this->headers); - } - - public static function parse(HttpHeader $header): TrailerHeader { - $raw = explode(',', $header->getFirstLine()); - $headers = []; - - foreach($raw as $header) - $headers[] = strtolower(trim($header)); - - return new TrailerHeader(array_unique($headers)); - } -} diff --git a/src/Http/Headers/TransferEncodingHeader.php b/src/Http/Headers/TransferEncodingHeader.php deleted file mode 100644 index 506c7de..0000000 --- a/src/Http/Headers/TransferEncodingHeader.php +++ /dev/null @@ -1,29 +0,0 @@ -encodings = $encodings; - } - - public function getEncodings(): array { - return $this->encodings; - } - - public static function parse(HttpHeader $header): TransferEncodingHeader { - return new TransferEncodingHeader( - array_map( - fn($directive) => trim($directive), - explode(',', strtolower($header->getFirstLine())) - ) - ); - } -} diff --git a/src/Http/Headers/UpgradeHeader.php b/src/Http/Headers/UpgradeHeader.php deleted file mode 100644 index 3d272f5..0000000 --- a/src/Http/Headers/UpgradeHeader.php +++ /dev/null @@ -1,33 +0,0 @@ -protocols = $protocols; - } - - public function getProtocols(): array { - return $this->protocols; - } - - public function isAccepted(string $protocol): bool { - return in_array(strtolower($protocol), $this->protocols); - } - - public static function parse(HttpHeader $header): UpgradeHeader { - return new UpgradeHeader( - array_map( - fn($directive) => trim($directive), - explode(',', strtolower($header->getFirstLine())) - ) - ); - } -} diff --git a/src/Http/Headers/UpgradeInsecureRequestsHeader.php b/src/Http/Headers/UpgradeInsecureRequestsHeader.php deleted file mode 100644 index 9e66b3b..0000000 --- a/src/Http/Headers/UpgradeInsecureRequestsHeader.php +++ /dev/null @@ -1,24 +0,0 @@ -upgrade = $upgrade; - } - - public function shouldUpgrade(): bool { - return $this->upgrade; - } - - public static function parse(HttpHeader $header): UpgradeInsecureRequestsHeader { - return new UpgradeInsecureRequestsHeader($header->getFirstLine() === '1'); - } -} diff --git a/src/Http/Headers/UserAgentHeader.php b/src/Http/Headers/UserAgentHeader.php deleted file mode 100644 index 3db70d3..0000000 --- a/src/Http/Headers/UserAgentHeader.php +++ /dev/null @@ -1,29 +0,0 @@ -userAgent = $userAgent; - } - - public function getUserAgent(): string { - return $this->userAgent; - } - - public function __toString(): string { - return $this->userAgent; - } - - public static function parse(HttpHeader $header): UserAgentHeader { - return new UserAgentHeader(trim($header->getFirstLine())); - } -}