172 lines
6.8 KiB
PHP
172 lines
6.8 KiB
PHP
<?php
|
|
|
|
// SPDX-FileCopyrightText: 2004-2023 Ryan Parman, Sam Sneddon, Ryan McCue
|
|
// SPDX-FileCopyrightText: 2014 PHP Framework Interoperability Group
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace SimplePie\HTTP;
|
|
|
|
/**
|
|
* HTTP Response interface
|
|
*
|
|
* This interface must be interoperable with Psr\Http\Message\ResponseInterface
|
|
* @see https://www.php-fig.org/psr/psr-7/#33-psrhttpmessageresponseinterface
|
|
*
|
|
* @internal
|
|
*/
|
|
interface Response
|
|
{
|
|
/**
|
|
* Return the string representation of the permanent URI of the requested resource
|
|
* (the first location after a prefix of (only) permanent redirects).
|
|
*
|
|
* Depending on which components of the URI are present, the resulting
|
|
* string is either a full URI or relative reference according to RFC 3986,
|
|
* Section 4.1. The method concatenates the various components of the URI,
|
|
* using the appropriate delimiters:
|
|
*
|
|
* - If a scheme is present, it MUST be suffixed by ":".
|
|
* - If an authority is present, it MUST be prefixed by "//".
|
|
* - The path can be concatenated without delimiters. But there are two
|
|
* cases where the path has to be adjusted to make the URI reference
|
|
* valid as PHP does not allow to throw an exception in __toString():
|
|
* - If the path is rootless and an authority is present, the path MUST
|
|
* be prefixed by "/".
|
|
* - If the path is starting with more than one "/" and no authority is
|
|
* present, the starting slashes MUST be reduced to one.
|
|
* - If a query is present, it MUST be prefixed by "?".
|
|
* - If a fragment is present, it MUST be prefixed by "#".
|
|
*
|
|
* @see http://tools.ietf.org/html/rfc3986#section-4.1
|
|
*/
|
|
public function get_permanent_uri(): string;
|
|
|
|
/**
|
|
* Return the string representation of the final requested URL after following all redirects.
|
|
*
|
|
* Depending on which components of the URI are present, the resulting
|
|
* string is either a full URI or relative reference according to RFC 3986,
|
|
* Section 4.1. The method concatenates the various components of the URI,
|
|
* using the appropriate delimiters:
|
|
*
|
|
* - If a scheme is present, it MUST be suffixed by ":".
|
|
* - If an authority is present, it MUST be prefixed by "//".
|
|
* - The path can be concatenated without delimiters. But there are two
|
|
* cases where the path has to be adjusted to make the URI reference
|
|
* valid as PHP does not allow to throw an exception in __toString():
|
|
* - If the path is rootless and an authority is present, the path MUST
|
|
* be prefixed by "/".
|
|
* - If the path is starting with more than one "/" and no authority is
|
|
* present, the starting slashes MUST be reduced to one.
|
|
* - If a query is present, it MUST be prefixed by "?".
|
|
* - If a fragment is present, it MUST be prefixed by "#".
|
|
*
|
|
* @see http://tools.ietf.org/html/rfc3986#section-4.1
|
|
*/
|
|
public function get_final_requested_uri(): string;
|
|
|
|
/**
|
|
* Gets the response status code.
|
|
*
|
|
* The status code is a 3-digit integer result code of the server's attempt
|
|
* to understand and satisfy the request.
|
|
*
|
|
* @return int Status code.
|
|
*/
|
|
public function get_status_code(): int;
|
|
|
|
/**
|
|
* Retrieves all message header values.
|
|
*
|
|
* The keys represent the header name as it will be sent over the wire, and
|
|
* each value is an array of strings associated with the header.
|
|
*
|
|
* // Represent the headers as a string
|
|
* foreach ($message->get_headers() as $name => $values) {
|
|
* echo $name . ': ' . implode(', ', $values);
|
|
* }
|
|
*
|
|
* // Emit headers iteratively:
|
|
* foreach ($message->get_headers() as $name => $values) {
|
|
* foreach ($values as $value) {
|
|
* header(sprintf('%s: %s', $name, $value), false);
|
|
* }
|
|
* }
|
|
*
|
|
* @return array<non-empty-array<string>> Returns an associative array of the message's headers.
|
|
* Each key MUST be a header name, and each value MUST be an array of
|
|
* strings for that header.
|
|
*/
|
|
public function get_headers(): array;
|
|
|
|
/**
|
|
* Checks if a header exists by the given case-insensitive name.
|
|
*
|
|
* @param string $name Case-insensitive header field name.
|
|
* @return bool Returns true if any header names match the given header
|
|
* name using a case-insensitive string comparison. Returns false if
|
|
* no matching header name is found in the message.
|
|
*/
|
|
public function has_header(string $name): bool;
|
|
|
|
/**
|
|
* Retrieves a message header value by the given case-insensitive name.
|
|
*
|
|
* This method returns an array of all the header values of the given
|
|
* case-insensitive header name.
|
|
*
|
|
* If the header does not appear in the message, this method MUST return an
|
|
* empty array.
|
|
*
|
|
* @param string $name Case-insensitive header field name.
|
|
* @return string[] An array of string values as provided for the given
|
|
* header. If the header does not appear in the message, this method MUST
|
|
* return an empty array.
|
|
*/
|
|
public function get_header(string $name): array;
|
|
|
|
/**
|
|
* Return an instance with the provided value replacing the specified header.
|
|
*
|
|
* This method MUST be implemented in such a way as to retain the
|
|
* immutability of the message, and MUST return an instance that has the
|
|
* new and/or updated header and value.
|
|
*
|
|
* @param string $name Case-insensitive header field name.
|
|
* @param string|non-empty-array<string> $value Header value(s).
|
|
* @return static
|
|
* @throws \InvalidArgumentException for invalid header names or values.
|
|
*/
|
|
public function with_header(string $name, $value);
|
|
|
|
/**
|
|
* Retrieves a comma-separated string of the values for a single header.
|
|
*
|
|
* This method returns all of the header values of the given
|
|
* case-insensitive header name as a string concatenated together using
|
|
* a comma.
|
|
*
|
|
* NOTE: Not all header values may be appropriately represented using
|
|
* comma concatenation. For such headers, use getHeader() instead
|
|
* and supply your own delimiter when concatenating.
|
|
*
|
|
* If the header does not appear in the message, this method MUST return
|
|
* an empty string.
|
|
*
|
|
* @param string $name Case-insensitive header field name.
|
|
* @return string A string of values as provided for the given header
|
|
* concatenated together using a comma. If the header does not appear in
|
|
* the message, this method MUST return an empty string.
|
|
*/
|
|
public function get_header_line(string $name): string;
|
|
|
|
/**
|
|
* get the body as string
|
|
*
|
|
* @return string
|
|
*/
|
|
public function get_body_content(): string;
|
|
}
|