Edit File by line

Deprecated: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in /home/sportsfever/public_html/filemanger/function.php on line 93
/home/sportsfe.../httpdocs/wp-conte.../plugins/wordpres.../vendor_p.../guzzleht.../psr7/src
File: Message.php
<?php
[0] Fix | Delete
[1] Fix | Delete
declare (strict_types=1);
[2] Fix | Delete
namespace YoastSEO_Vendor\GuzzleHttp\Psr7;
[3] Fix | Delete
[4] Fix | Delete
use YoastSEO_Vendor\Psr\Http\Message\MessageInterface;
[5] Fix | Delete
use YoastSEO_Vendor\Psr\Http\Message\RequestInterface;
[6] Fix | Delete
use YoastSEO_Vendor\Psr\Http\Message\ResponseInterface;
[7] Fix | Delete
final class Message
[8] Fix | Delete
{
[9] Fix | Delete
/**
[10] Fix | Delete
* Returns the string representation of an HTTP message.
[11] Fix | Delete
*
[12] Fix | Delete
* @param MessageInterface $message Message to convert to a string.
[13] Fix | Delete
*/
[14] Fix | Delete
public static function toString(\YoastSEO_Vendor\Psr\Http\Message\MessageInterface $message) : string
[15] Fix | Delete
{
[16] Fix | Delete
if ($message instanceof \YoastSEO_Vendor\Psr\Http\Message\RequestInterface) {
[17] Fix | Delete
$msg = \trim($message->getMethod() . ' ' . $message->getRequestTarget()) . ' HTTP/' . $message->getProtocolVersion();
[18] Fix | Delete
if (!$message->hasHeader('host')) {
[19] Fix | Delete
$msg .= "\r\nHost: " . $message->getUri()->getHost();
[20] Fix | Delete
}
[21] Fix | Delete
} elseif ($message instanceof \YoastSEO_Vendor\Psr\Http\Message\ResponseInterface) {
[22] Fix | Delete
$msg = 'HTTP/' . $message->getProtocolVersion() . ' ' . $message->getStatusCode() . ' ' . $message->getReasonPhrase();
[23] Fix | Delete
} else {
[24] Fix | Delete
throw new \InvalidArgumentException('Unknown message type');
[25] Fix | Delete
}
[26] Fix | Delete
foreach ($message->getHeaders() as $name => $values) {
[27] Fix | Delete
if (\is_string($name) && \strtolower($name) === 'set-cookie') {
[28] Fix | Delete
foreach ($values as $value) {
[29] Fix | Delete
$msg .= "\r\n{$name}: " . $value;
[30] Fix | Delete
}
[31] Fix | Delete
} else {
[32] Fix | Delete
$msg .= "\r\n{$name}: " . \implode(', ', $values);
[33] Fix | Delete
}
[34] Fix | Delete
}
[35] Fix | Delete
return "{$msg}\r\n\r\n" . $message->getBody();
[36] Fix | Delete
}
[37] Fix | Delete
/**
[38] Fix | Delete
* Get a short summary of the message body.
[39] Fix | Delete
*
[40] Fix | Delete
* Will return `null` if the response is not printable.
[41] Fix | Delete
*
[42] Fix | Delete
* @param MessageInterface $message The message to get the body summary
[43] Fix | Delete
* @param int $truncateAt The maximum allowed size of the summary
[44] Fix | Delete
*/
[45] Fix | Delete
public static function bodySummary(\YoastSEO_Vendor\Psr\Http\Message\MessageInterface $message, int $truncateAt = 120) : ?string
[46] Fix | Delete
{
[47] Fix | Delete
$body = $message->getBody();
[48] Fix | Delete
if (!$body->isSeekable() || !$body->isReadable()) {
[49] Fix | Delete
return null;
[50] Fix | Delete
}
[51] Fix | Delete
$size = $body->getSize();
[52] Fix | Delete
if ($size === 0) {
[53] Fix | Delete
return null;
[54] Fix | Delete
}
[55] Fix | Delete
$body->rewind();
[56] Fix | Delete
$summary = $body->read($truncateAt);
[57] Fix | Delete
$body->rewind();
[58] Fix | Delete
if ($size > $truncateAt) {
[59] Fix | Delete
$summary .= ' (truncated...)';
[60] Fix | Delete
}
[61] Fix | Delete
// Matches any printable character, including unicode characters:
[62] Fix | Delete
// letters, marks, numbers, punctuation, spacing, and separators.
[63] Fix | Delete
if (\preg_match('/[^\\pL\\pM\\pN\\pP\\pS\\pZ\\n\\r\\t]/u', $summary) !== 0) {
[64] Fix | Delete
return null;
[65] Fix | Delete
}
[66] Fix | Delete
return $summary;
[67] Fix | Delete
}
[68] Fix | Delete
/**
[69] Fix | Delete
* Attempts to rewind a message body and throws an exception on failure.
[70] Fix | Delete
*
[71] Fix | Delete
* The body of the message will only be rewound if a call to `tell()`
[72] Fix | Delete
* returns a value other than `0`.
[73] Fix | Delete
*
[74] Fix | Delete
* @param MessageInterface $message Message to rewind
[75] Fix | Delete
*
[76] Fix | Delete
* @throws \RuntimeException
[77] Fix | Delete
*/
[78] Fix | Delete
public static function rewindBody(\YoastSEO_Vendor\Psr\Http\Message\MessageInterface $message) : void
[79] Fix | Delete
{
[80] Fix | Delete
$body = $message->getBody();
[81] Fix | Delete
if ($body->tell()) {
[82] Fix | Delete
$body->rewind();
[83] Fix | Delete
}
[84] Fix | Delete
}
[85] Fix | Delete
/**
[86] Fix | Delete
* Parses an HTTP message into an associative array.
[87] Fix | Delete
*
[88] Fix | Delete
* The array contains the "start-line" key containing the start line of
[89] Fix | Delete
* the message, "headers" key containing an associative array of header
[90] Fix | Delete
* array values, and a "body" key containing the body of the message.
[91] Fix | Delete
*
[92] Fix | Delete
* @param string $message HTTP request or response to parse.
[93] Fix | Delete
*/
[94] Fix | Delete
public static function parseMessage(string $message) : array
[95] Fix | Delete
{
[96] Fix | Delete
if (!$message) {
[97] Fix | Delete
throw new \InvalidArgumentException('Invalid message');
[98] Fix | Delete
}
[99] Fix | Delete
$message = \ltrim($message, "\r\n");
[100] Fix | Delete
$messageParts = \preg_split("/\r?\n\r?\n/", $message, 2);
[101] Fix | Delete
if ($messageParts === \false || \count($messageParts) !== 2) {
[102] Fix | Delete
throw new \InvalidArgumentException('Invalid message: Missing header delimiter');
[103] Fix | Delete
}
[104] Fix | Delete
[$rawHeaders, $body] = $messageParts;
[105] Fix | Delete
$rawHeaders .= "\r\n";
[106] Fix | Delete
// Put back the delimiter we split previously
[107] Fix | Delete
$headerParts = \preg_split("/\r?\n/", $rawHeaders, 2);
[108] Fix | Delete
if ($headerParts === \false || \count($headerParts) !== 2) {
[109] Fix | Delete
throw new \InvalidArgumentException('Invalid message: Missing status line');
[110] Fix | Delete
}
[111] Fix | Delete
[$startLine, $rawHeaders] = $headerParts;
[112] Fix | Delete
if (\preg_match("/(?:^HTTP\\/|^[A-Z]+ \\S+ HTTP\\/)(\\d+(?:\\.\\d+)?)/i", $startLine, $matches) && $matches[1] === '1.0') {
[113] Fix | Delete
// Header folding is deprecated for HTTP/1.1, but allowed in HTTP/1.0
[114] Fix | Delete
$rawHeaders = \preg_replace(\YoastSEO_Vendor\GuzzleHttp\Psr7\Rfc7230::HEADER_FOLD_REGEX, ' ', $rawHeaders);
[115] Fix | Delete
}
[116] Fix | Delete
/** @var array[] $headerLines */
[117] Fix | Delete
$count = \preg_match_all(\YoastSEO_Vendor\GuzzleHttp\Psr7\Rfc7230::HEADER_REGEX, $rawHeaders, $headerLines, \PREG_SET_ORDER);
[118] Fix | Delete
// If these aren't the same, then one line didn't match and there's an invalid header.
[119] Fix | Delete
if ($count !== \substr_count($rawHeaders, "\n")) {
[120] Fix | Delete
// Folding is deprecated, see https://datatracker.ietf.org/doc/html/rfc7230#section-3.2.4
[121] Fix | Delete
if (\preg_match(\YoastSEO_Vendor\GuzzleHttp\Psr7\Rfc7230::HEADER_FOLD_REGEX, $rawHeaders)) {
[122] Fix | Delete
throw new \InvalidArgumentException('Invalid header syntax: Obsolete line folding');
[123] Fix | Delete
}
[124] Fix | Delete
throw new \InvalidArgumentException('Invalid header syntax');
[125] Fix | Delete
}
[126] Fix | Delete
$headers = [];
[127] Fix | Delete
foreach ($headerLines as $headerLine) {
[128] Fix | Delete
$headers[$headerLine[1]][] = $headerLine[2];
[129] Fix | Delete
}
[130] Fix | Delete
return ['start-line' => $startLine, 'headers' => $headers, 'body' => $body];
[131] Fix | Delete
}
[132] Fix | Delete
/**
[133] Fix | Delete
* Constructs a URI for an HTTP request message.
[134] Fix | Delete
*
[135] Fix | Delete
* @param string $path Path from the start-line
[136] Fix | Delete
* @param array $headers Array of headers (each value an array).
[137] Fix | Delete
*/
[138] Fix | Delete
public static function parseRequestUri(string $path, array $headers) : string
[139] Fix | Delete
{
[140] Fix | Delete
$hostKey = \array_filter(\array_keys($headers), function ($k) {
[141] Fix | Delete
// Numeric array keys are converted to int by PHP.
[142] Fix | Delete
$k = (string) $k;
[143] Fix | Delete
return \strtolower($k) === 'host';
[144] Fix | Delete
});
[145] Fix | Delete
// If no host is found, then a full URI cannot be constructed.
[146] Fix | Delete
if (!$hostKey) {
[147] Fix | Delete
return $path;
[148] Fix | Delete
}
[149] Fix | Delete
$host = $headers[\reset($hostKey)][0];
[150] Fix | Delete
$scheme = \substr($host, -4) === ':443' ? 'https' : 'http';
[151] Fix | Delete
return $scheme . '://' . $host . '/' . \ltrim($path, '/');
[152] Fix | Delete
}
[153] Fix | Delete
/**
[154] Fix | Delete
* Parses a request message string into a request object.
[155] Fix | Delete
*
[156] Fix | Delete
* @param string $message Request message string.
[157] Fix | Delete
*/
[158] Fix | Delete
public static function parseRequest(string $message) : \YoastSEO_Vendor\Psr\Http\Message\RequestInterface
[159] Fix | Delete
{
[160] Fix | Delete
$data = self::parseMessage($message);
[161] Fix | Delete
$matches = [];
[162] Fix | Delete
if (!\preg_match('/^[\\S]+\\s+([a-zA-Z]+:\\/\\/|\\/).*/', $data['start-line'], $matches)) {
[163] Fix | Delete
throw new \InvalidArgumentException('Invalid request string');
[164] Fix | Delete
}
[165] Fix | Delete
$parts = \explode(' ', $data['start-line'], 3);
[166] Fix | Delete
$version = isset($parts[2]) ? \explode('/', $parts[2])[1] : '1.1';
[167] Fix | Delete
$request = new \YoastSEO_Vendor\GuzzleHttp\Psr7\Request($parts[0], $matches[1] === '/' ? self::parseRequestUri($parts[1], $data['headers']) : $parts[1], $data['headers'], $data['body'], $version);
[168] Fix | Delete
return $matches[1] === '/' ? $request : $request->withRequestTarget($parts[1]);
[169] Fix | Delete
}
[170] Fix | Delete
/**
[171] Fix | Delete
* Parses a response message string into a response object.
[172] Fix | Delete
*
[173] Fix | Delete
* @param string $message Response message string.
[174] Fix | Delete
*/
[175] Fix | Delete
public static function parseResponse(string $message) : \YoastSEO_Vendor\Psr\Http\Message\ResponseInterface
[176] Fix | Delete
{
[177] Fix | Delete
$data = self::parseMessage($message);
[178] Fix | Delete
// According to https://datatracker.ietf.org/doc/html/rfc7230#section-3.1.2
[179] Fix | Delete
// the space between status-code and reason-phrase is required. But
[180] Fix | Delete
// browsers accept responses without space and reason as well.
[181] Fix | Delete
if (!\preg_match('/^HTTP\\/.* [0-9]{3}( .*|$)/', $data['start-line'])) {
[182] Fix | Delete
throw new \InvalidArgumentException('Invalid response string: ' . $data['start-line']);
[183] Fix | Delete
}
[184] Fix | Delete
$parts = \explode(' ', $data['start-line'], 3);
[185] Fix | Delete
return new \YoastSEO_Vendor\GuzzleHttp\Psr7\Response((int) $parts[1], $data['headers'], $data['body'], \explode('/', $parts[0])[1], $parts[2] ?? null);
[186] Fix | Delete
}
[187] Fix | Delete
}
[188] Fix | Delete
[189] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function