Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add headers parsing #22

Open
wants to merge 29 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 27 commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
fe0f61a
draft :: first iteration
roxblnfk Feb 23, 2020
1a954d9
draft :: second iteration
roxblnfk Feb 26, 2020
cac8cab
draft :: next iteration
roxblnfk Feb 26, 2020
bdd0ca7
More tests
roxblnfk Feb 27, 2020
63b61ed
more tests and fixes
roxblnfk Feb 27, 2020
d6d9f08
added tests; fixes
roxblnfk Feb 28, 2020
a65abeb
Refactoring; Added ParsingException
roxblnfk Feb 29, 2020
3740a76
added some header values
roxblnfk Mar 2, 2020
fb60232
Added sorting method for values with quality param
roxblnfk Mar 2, 2020
9f3cb05
added AcceptHeader; refactoring
roxblnfk Mar 3, 2020
1805477
added Russian description draft; some refactoring
roxblnfk Mar 3, 2020
1b0f63d
Documentation is now separated; more tests; more refactoring
roxblnfk Mar 4, 2020
2196232
Header class now immutable; more refactoring; added cache headers and…
roxblnfk Mar 5, 2020
fadb06c
Added ETag header
roxblnfk Mar 7, 2020
18f6ee9
added logic for CacheControl and Pragma headers
roxblnfk Mar 9, 2020
5264910
Added CacheControlHeader; docs updated; Date improvements
roxblnfk Mar 12, 2020
e0a5dd6
Docs updated; Added methods CONNECT and TRACE; Interfaces moved to `R…
roxblnfk Mar 16, 2020
99090e1
Added logic into Age and Warning headers; @see replaced to @link
roxblnfk Mar 19, 2020
1e0b298
Merge remote-tracking branch 'upstream/master' into feature/http-headers
roxblnfk Mar 30, 2020
784bd80
Refactoring: removed parsing interfaces; parsing params declared in c…
roxblnfk Apr 1, 2020
44717d6
Refactoring: unnamed header values moved to Unnamed namespace; Parser…
roxblnfk Apr 1, 2020
710a8cd
Added `inject` method in the `BaseHeaderValue` class
roxblnfk Apr 2, 2020
8d7c391
Fix doc
roxblnfk Dec 5, 2020
a77792e
Merge branch 'master-upstream' into feature/http-headers
roxblnfk Dec 5, 2020
d88433e
Merge branch 'master-upstream' into feature/http-headers
roxblnfk Feb 25, 2021
3ae5915
Add psr/http-message again; cleanup
roxblnfk Feb 25, 2021
27609a4
Cleanup
roxblnfk Feb 25, 2021
afeaf21
Fix some codestyle
roxblnfk Feb 26, 2021
3ae1418
Apply cs diff
roxblnfk Feb 26, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
83 changes: 3 additions & 80 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,87 +20,10 @@ The package provides:
- PSR-7, PSR-17 PhpStorm meta for HTTP protocol headers, methods and statuses.
- `ContentDispositionHeader` that has static methods to generate `Content-Disposition` header name and value.

## Method constants
## Documentation

Individual HTTP methods could be referenced as

```php
use Yiisoft\Http\Method;

Method::GET;
Method::POST;
Method::PUT;
Method::DELETE;
Method::PATCH;
Method::HEAD;
Method::OPTIONS;
```

To have a list of these, use:

```php
use Yiisoft\Http\Method;

Method::ALL;
```

## HTTP status codes

Status codes could be referenced by name as:

```php
use Yiisoft\Http\Status;

Status::NOT_FOUND;
```

Status text could be obtained as the following:

```php
use Yiisoft\Http\Status;

Status::TEXTS[Status::NOT_FOUND];
```

## `ContentDispositionHeader` usage

`ContentDispositionHeader` methods are static so usage is like the following:

```php
$name = \Yiisoft\Http\ContentDispositionHeader::name();

$value = \Yiisoft\Http\ContentDispositionHeader::value(
\Yiisoft\Http\ContentDispositionHeader::INLINE,
'avatar.png'
);

$value = \Yiisoft\Http\ContentDispositionHeader::inline('document.pdf');

$value = \Yiisoft\Http\ContentDispositionHeader::attachment('document.pdf');
```

## PSR-7 and PSR-17 PhpStorm meta

The package includes PhpStorm meta-files that help IDE to provide values when completing code in cases such as:

```php
use Psr\Http\Message\ResponseFactoryInterface;
use Psr\Http\Message\ResponseInterface;
use Yiisoft\Http\Header;
use Yiisoft\Http\Status;

class StaticController
{
private ResponseFactoryInterface $responseFactory;

public function actionIndex(): ResponseInterface
{
return $this->responseFactory->createResponse()
->withStatus(Status::OK)
->withoutHeader(Header::ACCEPT);
}
}
```
- [English](docs/en/README.md)
- [Russian](docs/ru/README.md)

## Testing

Expand Down
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
},
"require": {
"php": "^7.4|^8.0",
"psr/http-message": "^1.0",
"yiisoft/strings": "^2.0"
},
"autoload": {
Expand Down
18 changes: 18 additions & 0 deletions docs/en/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# HTTP Package

All HTTP/1.1 messages consist of a start-line followed by a sequence of octets in a format similar to the Internet
Message Format [RFC5322](https://tools.ietf.org/html/rfc5322): zero or more header fields (collectively referred to as
the "headers" or the "header section"), an empty line indicating the end of the header section, and an optional message
body.

- [HTTP start line](http-start-line.md) (Method constants and status codes)
- [HTTP headers](http-headers.md)

Related links to RFC:

* [RFC7230](https://tools.ietf.org/html/rfc7230) HTTP/1.1: Message Syntax and Routing
* [RFC7231](https://tools.ietf.org/html/rfc7231) HTTP/1.1: Semantics and Content
* [RFC7232](https://tools.ietf.org/html/rfc7232) HTTP/1.1: Conditional Requests
* [RFC7233](https://tools.ietf.org/html/rfc7233) HTTP/1.1: Range Requests
* [RFC7234](https://tools.ietf.org/html/rfc7234) HTTP/1.1: Caching
* [RFC7235](https://tools.ietf.org/html/rfc7235) HTTP/1.1: Authentication
87 changes: 87 additions & 0 deletions docs/en/http-start-line.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
# HTTP start line

An HTTP message can be either a request from client to server or a response from server to client. Syntactically, the
two types of message differ in the start-line, which is either a request-line (for requests) or a status-line
(for responses).

## Method constants

Individual HTTP methods could be referenced as

```php
use Yiisoft\Http\Method;

Method::GET;
Method::POST;
Method::PUT;
Method::DELETE;
Method::PATCH;
Method::HEAD;
Method::OPTIONS;
```

To have a list of these, use:

```php
use Yiisoft\Http\Method;

Method::ALL;
```

## HTTP status codes

Status codes could be referenced by name as:

```php
use Yiisoft\Http\Status;

Status::NOT_FOUND;
```

Status text could be obtained as the following:

```php
use Yiisoft\Http\Status;

Status::TEXTS[Status::NOT_FOUND];
```

# ContentDispositionHeader usage

`ContentDispositionHeader` methods are static so usage is like the following:

```php
$name = \Yiisoft\Http\ContentDispositionHeader::name();

$value = \Yiisoft\Http\ContentDispositionHeader::value(
\Yiisoft\Http\ContentDispositionHeader::INLINE,
'avatar.png'
);

$value = \Yiisoft\Http\ContentDispositionHeader::inline('document.pdf');

$value = \Yiisoft\Http\ContentDispositionHeader::attachment('document.pdf');
```

# PSR-7 and PSR-17 PhpStorm meta

The package includes PhpStorm meta-files that help IDE to provide values when completing code in cases such as:

```php
use Psr\Http\Message\ResponseFactoryInterface;
use Psr\Http\Message\ResponseInterface;
use Yiisoft\Http\Header;
use Yiisoft\Http\Status;

class StaticController
{
private ResponseFactoryInterface $responseFactory;

public function actionIndex(): ResponseInterface
{
return $this->responseFactory->createResponse()
->withStatus(Status::OK)
->withoutHeader(Header::ACCEPT);
}
}
```
18 changes: 18 additions & 0 deletions docs/ru/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# HTTP Package

All HTTP/1.1 messages consist of a start-line followed by a sequence of octets in a format similar to the Internet
samdark marked this conversation as resolved.
Show resolved Hide resolved
Message Format [RFC5322](https://tools.ietf.org/html/rfc5322): zero or more header fields (collectively referred to as
the "headers" or the "header section"), an empty line indicating the end of the header section, and an optional message
body.

- [HTTP start line](http-start-line.md) (Method constants and status codes)
- [HTTP заголовки](http-headers.md)

Ссылки на RFC:

* [RFC7230](https://tools.ietf.org/html/rfc7230) HTTP/1.1: Message Syntax and Routing
* [RFC7231](https://tools.ietf.org/html/rfc7231) HTTP/1.1: Semantics and Content
* [RFC7232](https://tools.ietf.org/html/rfc7232) HTTP/1.1: Conditional Requests
* [RFC7233](https://tools.ietf.org/html/rfc7233) HTTP/1.1: Range Requests
* [RFC7234](https://tools.ietf.org/html/rfc7234) HTTP/1.1: Caching
* [RFC7235](https://tools.ietf.org/html/rfc7235) HTTP/1.1: Authentication
Loading