sunrise-php /
http-message
| 1 | <?php declare(strict_types=1); |
||
| 2 | |||
| 3 | /** |
||
| 4 | * It's free open-source software released under the MIT License. |
||
| 5 | * |
||
| 6 | * @author Anatoly Nekhay <[email protected]> |
||
| 7 | * @copyright Copyright (c) 2018, Anatoly Nekhay |
||
| 8 | * @license https://github.com/sunrise-php/http-message/blob/master/LICENSE |
||
| 9 | * @link https://github.com/sunrise-php/http-message |
||
| 10 | */ |
||
| 11 | |||
| 12 | namespace Sunrise\Http\Message; |
||
| 13 | |||
| 14 | use function sprintf; |
||
| 15 | use function sscanf; |
||
| 16 | |||
| 17 | /** |
||
| 18 | * @link https://datatracker.ietf.org/doc/html/rfc3875#section-4.1.16 |
||
| 19 | */ |
||
| 20 | function server_request_protocol_version(?array $serverParams = null): string |
||
| 21 | { |
||
| 22 | 59 | $serverParams ??= $_SERVER; |
|
| 23 | |||
| 24 | 59 | if (!isset($serverParams['SERVER_PROTOCOL'])) { |
|
| 25 | 47 | return '1.1'; |
|
| 26 | } |
||
| 27 | |||
| 28 | // "HTTP" "/" 1*digit "." 1*digit |
||
| 29 | 12 | sscanf($serverParams['SERVER_PROTOCOL'], 'HTTP/%d.%d', $major, $minor); |
|
|
0 ignored issues
–
show
Comprehensibility
Best Practice
introduced
by
Loading history...
|
|||
| 30 | |||
| 31 | // e.g.: HTTP/1.1 |
||
| 32 | 12 | if (isset($minor)) { |
|
|
0 ignored issues
–
show
Comprehensibility
Best Practice
introduced
by
|
|||
| 33 | 6 | return sprintf('%d.%d', $major, $minor); |
|
| 34 | } |
||
| 35 | |||
| 36 | // e.g.: HTTP/2 |
||
| 37 | 6 | if (isset($major)) { |
|
| 38 | 2 | return sprintf('%d', $major); |
|
| 39 | } |
||
| 40 | |||
| 41 | 4 | return '1.1'; |
|
| 42 | } |
||
| 43 |