Skip to content

Commit

Permalink
add access to normalized header values
Browse files Browse the repository at this point in the history
  • Loading branch information
Baptouuuu committed Feb 17, 2023
1 parent af9e58c commit 287159d
Show file tree
Hide file tree
Showing 35 changed files with 201 additions and 1 deletion.
26 changes: 26 additions & 0 deletions CHANGELOG.md
@@ -1,5 +1,31 @@
# Changelog

## 6.1.0 - 2023-02-17

### Added

- `Innmind\Http\Header\Age::age()`
- `Innmind\Http\Header\AgeValue::age()`
- `Innmind\Http\Header\Authorization::scheme()`
- `Innmind\Http\Header\Authorization::parameter()`
- `Innmind\Http\Header\ContentLength::length()`
- `Innmind\Http\Header\ContentLengthValue::length()`
- `Innmind\Http\Header\ContentLocation::url()`
- `Innmind\Http\Header\ContentRange::range()`
- `Innmind\Http\Header\ContentType::content()`
- `Innmind\Http\Header\Cookie::parameters()`
- `Innmind\Http\Header\Date::date()`
- `Innmind\Http\Header\DateValue::date()`
- `Innmind\Http\Header\Expires::date()`
- `Innmind\Http\Header\Host::host()`
- `Innmind\Http\Header\Host::port()`
- `Innmind\Http\Header\IfModifiedSince::date()`
- `Innmind\Http\Header\IfUnmodifiedSince::date()`
- `Innmind\Http\Header\LastModified::date()`
- `Innmind\Http\Header\Range::range()`
- `Innmind\Http\Header\Referrer::referrer()`
- `Innmind\Http\Header\ReferrerValue::url()`

## 6.0.1 - 2023-02-12

### Fixed
Expand Down
10 changes: 10 additions & 0 deletions src/Header/Age.php
Expand Up @@ -12,10 +12,12 @@
final class Age implements HeaderInterface
{
private Header $header;
private AgeValue $value;

public function __construct(AgeValue $age)
{
$this->header = new Header('Age', $age);
$this->value = $age;
}

/**
Expand All @@ -36,6 +38,14 @@ public function values(): Set
return $this->header->values();
}

/**
* @return 0|positive-int
*/
public function age(): int
{
return $this->value->age();
}

public function toString(): string
{
return $this->header->toString();
Expand Down
10 changes: 10 additions & 0 deletions src/Header/AgeValue.php
Expand Up @@ -11,6 +11,7 @@
*/
final class AgeValue implements Value
{
/** @var 0|positive-int */
private int $age;

public function __construct(int $age)
Expand All @@ -19,6 +20,7 @@ public function __construct(int $age)
throw new DomainException((string) $age);
}

/** @var 0|positive-int */
$this->age = $age;
}

Expand All @@ -37,6 +39,14 @@ public static function of(int $age): Maybe
}
}

/**
* @return 0|positive-int
*/
public function age(): int
{
return $this->age;
}

public function toString(): string
{
return (string) $this->age;
Expand Down
12 changes: 12 additions & 0 deletions src/Header/Authorization.php
Expand Up @@ -12,10 +12,12 @@
final class Authorization implements HeaderInterface
{
private Header $header;
private AuthorizationValue $value;

public function __construct(AuthorizationValue $authorization)
{
$this->header = new Header('Authorization', $authorization);
$this->value = $authorization;
}

/**
Expand All @@ -36,6 +38,16 @@ public function values(): Set
return $this->header->values();
}

public function scheme(): string
{
return $this->value->scheme();
}

public function parameter(): string
{
return $this->value->parameter();
}

public function toString(): string
{
return $this->header->toString();
Expand Down
10 changes: 10 additions & 0 deletions src/Header/ContentLength.php
Expand Up @@ -12,10 +12,12 @@
final class ContentLength implements HeaderInterface
{
private Header $header;
private ContentLengthValue $value;

public function __construct(ContentLengthValue $length)
{
$this->header = new Header('Content-Length', $length);
$this->value = $length;
}

/**
Expand All @@ -36,6 +38,14 @@ public function values(): Set
return $this->header->values();
}

/**
* @return 0|positive-int
*/
public function length(): int
{
return $this->value->length();
}

public function toString(): string
{
return $this->header->toString();
Expand Down
10 changes: 10 additions & 0 deletions src/Header/ContentLengthValue.php
Expand Up @@ -11,6 +11,7 @@
*/
final class ContentLengthValue implements Value
{
/** @var 0|positive-int */
private int $length;

public function __construct(int $length)
Expand All @@ -19,6 +20,7 @@ public function __construct(int $length)
throw new DomainException((string) $length);
}

/** @var 0|positive-int */
$this->length = $length;
}

Expand All @@ -37,6 +39,14 @@ public static function of(int $length): Maybe
}
}

/**
* @return 0|positive-int
*/
public function length(): int
{
return $this->length;
}

public function toString(): string
{
return (string) $this->length;
Expand Down
7 changes: 7 additions & 0 deletions src/Header/ContentLocation.php
Expand Up @@ -13,10 +13,12 @@
final class ContentLocation implements HeaderInterface
{
private Header $header;
private LocationValue $value;

public function __construct(LocationValue $location)
{
$this->header = new Header('Content-Location', $location);
$this->value = $location;
}

/**
Expand All @@ -37,6 +39,11 @@ public function values(): Set
return $this->header->values();
}

public function url(): Url
{
return $this->value->url();
}

public function toString(): string
{
return $this->header->toString();
Expand Down
7 changes: 7 additions & 0 deletions src/Header/ContentRange.php
Expand Up @@ -12,10 +12,12 @@
final class ContentRange implements HeaderInterface
{
private Header $header;
private ContentRangeValue $range;

public function __construct(ContentRangeValue $range)
{
$this->header = new Header('Content-Range', $range);
$this->range = $range;
}

/**
Expand Down Expand Up @@ -45,6 +47,11 @@ public function values(): Set
return $this->header->values();
}

public function range(): ContentRangeValue
{
return $this->range;
}

public function toString(): string
{
return $this->header->toString();
Expand Down
7 changes: 7 additions & 0 deletions src/Header/ContentType.php
Expand Up @@ -12,10 +12,12 @@
final class ContentType implements HeaderInterface
{
private Header $header;
private ContentTypeValue $content;

public function __construct(ContentTypeValue $content)
{
$this->header = new Header('Content-Type', $content);
$this->content = $content;
}

/**
Expand Down Expand Up @@ -43,6 +45,11 @@ public function values(): Set
return $this->header->values();
}

public function content(): ContentTypeValue
{
return $this->content;
}

public function toString(): string
{
return $this->header->toString();
Expand Down
15 changes: 14 additions & 1 deletion src/Header/Cookie.php
Expand Up @@ -4,18 +4,23 @@
namespace Innmind\Http\Header;

use Innmind\Http\Header as HeaderInterface;
use Innmind\Immutable\Set;
use Innmind\Immutable\{
Set,
Map,
};

/**
* @psalm-immutable
*/
final class Cookie implements HeaderInterface
{
private Header $header;
private CookieValue $value;

public function __construct(CookieValue $value)
{
$this->header = new Header('Cookie', $value);
$this->value = $value;
}

/**
Expand All @@ -37,6 +42,14 @@ public function values(): Set
return $this->header->values();
}

/**
* @return Map<string, Parameter>
*/
public function parameters(): Map
{
return $this->value->parameters();
}

public function toString(): string
{
return $this->header->toString();
Expand Down
7 changes: 7 additions & 0 deletions src/Header/Date.php
Expand Up @@ -13,10 +13,12 @@
final class Date implements HeaderInterface
{
private Header $header;
private DateValue $value;

public function __construct(DateValue $date)
{
$this->header = new Header('Date', $date);
$this->value = $date;
}

/**
Expand All @@ -37,6 +39,11 @@ public function values(): Set
return $this->header->values();
}

public function date(): PointInTime
{
return $this->value->date();
}

public function toString(): string
{
return $this->header->toString();
Expand Down
5 changes: 5 additions & 0 deletions src/Header/DateValue.php
Expand Up @@ -21,6 +21,11 @@ public function __construct(PointInTime $date)
$this->date = $date;
}

public function date(): PointInTime
{
return $this->date;
}

public function toString(): string
{
return $this->date->changeTimezone(new UTC)->format(new Http);
Expand Down
7 changes: 7 additions & 0 deletions src/Header/Expires.php
Expand Up @@ -13,10 +13,12 @@
final class Expires implements HeaderInterface
{
private Header $header;
private DateValue $value;

public function __construct(DateValue $date)
{
$this->header = new Header('Expires', $date);
$this->value = $date;
}

/**
Expand All @@ -37,6 +39,11 @@ public function values(): Set
return $this->header->values();
}

public function date(): PointInTime
{
return $this->value->date();
}

public function toString(): string
{
return $this->header->toString();
Expand Down
12 changes: 12 additions & 0 deletions src/Header/Host.php
Expand Up @@ -16,10 +16,12 @@
final class Host implements HeaderInterface
{
private Header $header;
private HostValue $value;

public function __construct(HostValue $host)
{
$this->header = new Header('Host', $host);
$this->value = $host;
}

/**
Expand All @@ -40,6 +42,16 @@ public function values(): Set
return $this->header->values();
}

public function host(): UrlHost
{
return $this->value->host();
}

public function port(): Port
{
return $this->value->port();
}

public function toString(): string
{
return $this->header->toString();
Expand Down

0 comments on commit 287159d

Please sign in to comment.