Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
CRAP | |
100.00% |
1 / 1 |
| HttpResponse | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |
100.00% |
1 / 1 |
| __construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| 1 | <?php |
| 2 | |
| 3 | /** |
| 4 | * SPDX-License-Identifier: EUPL-1.2 |
| 5 | * |
| 6 | * This file is part of icap-flow. |
| 7 | * |
| 8 | * Licensed under the EUPL, Version 1.2 only (the "Licence"); |
| 9 | * you may not use this work except in compliance with the Licence. |
| 10 | * You may obtain a copy of the Licence at: |
| 11 | * |
| 12 | * https://joinup.ec.europa.eu/collection/eupl/eupl-text-eupl-12 |
| 13 | * |
| 14 | * Unless required by applicable law or agreed to in writing, software |
| 15 | * distributed under the Licence is distributed on an "AS IS" basis, |
| 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 17 | */ |
| 18 | |
| 19 | declare(strict_types=1); |
| 20 | |
| 21 | namespace Ndrstmr\Icap\DTO; |
| 22 | |
| 23 | use Ndrstmr\Icap\LocalFile; |
| 24 | |
| 25 | /** |
| 26 | * Encapsulated HTTP response carried inside an ICAP RESPMOD request |
| 27 | * (RFC 3507 §4.9) or returned in a 200 response with modifications. |
| 28 | * |
| 29 | * Body is either a string (treated as raw bytes) or a stream resource the |
| 30 | * {@see \Ndrstmr\Icap\RequestFormatter} reads chunk-by-chunk to avoid |
| 31 | * buffering the whole payload in memory. A stream passed in stays the |
| 32 | * caller's: it is read, never closed. When the headers announce a |
| 33 | * `Content-Length`, the stream has to deliver exactly that many bytes, or |
| 34 | * sending the request fails before the final chunk. A preview that carries |
| 35 | * only the start of the body is the exception: the field describes all of it. |
| 36 | */ |
| 37 | final readonly class HttpResponse |
| 38 | { |
| 39 | /** |
| 40 | * @param int $statusCode HTTP status code, e.g. 200 |
| 41 | * @param string $reasonPhrase Reason phrase, e.g. "OK" |
| 42 | * @param array<string, string[]> $headers HTTP header list |
| 43 | * @param resource|string|LocalFile|null $body HTTP body bytes, or a readable stream resource, or null for header-only; |
| 44 | * scanFile() and scanFileWithPreview() hand over the {@see LocalFile} they opened |
| 45 | * @param string $httpVersion HTTP version label, default HTTP/1.1 |
| 46 | */ |
| 47 | public function __construct( |
| 48 | public int $statusCode, |
| 49 | public string $reasonPhrase = 'OK', |
| 50 | public array $headers = [], |
| 51 | public mixed $body = null, |
| 52 | public string $httpVersion = 'HTTP/1.1', |
| 53 | ) { |
| 54 | } |
| 55 | } |