mirror of
https://github.com/linuxserver/Heimdall.git
synced 2025-12-02 21:19:58 +09:00
Update to laravel 7
This commit is contained in:
@@ -17,16 +17,23 @@ class FullHttpMessageFormatter implements Formatter
|
||||
/**
|
||||
* The maximum length of the body.
|
||||
*
|
||||
* @var int
|
||||
* @var int|null
|
||||
*/
|
||||
private $maxBodyLength;
|
||||
|
||||
/**
|
||||
* @param int $maxBodyLength
|
||||
* @var string
|
||||
*/
|
||||
public function __construct($maxBodyLength = 1000)
|
||||
private $binaryDetectionRegex;
|
||||
|
||||
/**
|
||||
* @param int|null $maxBodyLength
|
||||
* @param string $binaryDetectionRegex By default, this is all non-printable ASCII characters and <DEL> except for \t, \r, \n
|
||||
*/
|
||||
public function __construct($maxBodyLength = 1000, string $binaryDetectionRegex = '/([\x00-\x09\x0C\x0E-\x1F\x7F])/')
|
||||
{
|
||||
$this->maxBodyLength = $maxBodyLength;
|
||||
$this->binaryDetectionRegex = $binaryDetectionRegex;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -67,25 +74,43 @@ class FullHttpMessageFormatter implements Formatter
|
||||
return $this->addBody($response, $message);
|
||||
}
|
||||
|
||||
/**
|
||||
* Formats a response in context of its request.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function formatResponseForRequest(ResponseInterface $response, RequestInterface $request)
|
||||
{
|
||||
return $this->formatResponse($response);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add the message body if the stream is seekable.
|
||||
*
|
||||
* @param MessageInterface $request
|
||||
* @param string $message
|
||||
* @param string $message
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
private function addBody(MessageInterface $request, $message)
|
||||
{
|
||||
$message .= "\n";
|
||||
$stream = $request->getBody();
|
||||
if (!$stream->isSeekable() || 0 === $this->maxBodyLength) {
|
||||
// Do not read the stream
|
||||
$message .= "\n";
|
||||
} else {
|
||||
$message .= "\n".mb_substr($stream->__toString(), 0, $this->maxBodyLength);
|
||||
$stream->rewind();
|
||||
return $message;
|
||||
}
|
||||
|
||||
return $message;
|
||||
$data = $stream->__toString();
|
||||
$stream->rewind();
|
||||
|
||||
if (preg_match($this->binaryDetectionRegex, $data)) {
|
||||
return $message.'[binary stream omitted]';
|
||||
}
|
||||
|
||||
if (null === $this->maxBodyLength) {
|
||||
return $message.$data;
|
||||
}
|
||||
|
||||
return $message.mb_substr($data, 0, $this->maxBodyLength);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user