mirror of
https://github.com/linuxserver/Heimdall.git
synced 2025-12-04 14:10:00 +09:00
changes
This commit is contained in:
91
vendor/php-http/message/src/Formatter/CurlCommandFormatter.php
vendored
Normal file
91
vendor/php-http/message/src/Formatter/CurlCommandFormatter.php
vendored
Normal file
@@ -0,0 +1,91 @@
|
||||
<?php
|
||||
|
||||
namespace Http\Message\Formatter;
|
||||
|
||||
use Http\Message\Formatter;
|
||||
use Psr\Http\Message\RequestInterface;
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
|
||||
/**
|
||||
* A formatter that prints a cURL command for HTTP requests.
|
||||
*
|
||||
* @author Tobias Nyholm <tobias.nyholm@gmail.com>
|
||||
*/
|
||||
class CurlCommandFormatter implements Formatter
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function formatRequest(RequestInterface $request)
|
||||
{
|
||||
$command = sprintf('curl %s', escapeshellarg((string) $request->getUri()->withFragment('')));
|
||||
if ('1.0' === $request->getProtocolVersion()) {
|
||||
$command .= ' --http1.0';
|
||||
} elseif ('2.0' === $request->getProtocolVersion()) {
|
||||
$command .= ' --http2';
|
||||
}
|
||||
|
||||
$method = strtoupper($request->getMethod());
|
||||
if ('HEAD' === $method) {
|
||||
$command .= ' --head';
|
||||
} elseif ('GET' !== $method) {
|
||||
$command .= ' --request '.$method;
|
||||
}
|
||||
|
||||
$command .= $this->getHeadersAsCommandOptions($request);
|
||||
|
||||
$body = $request->getBody();
|
||||
if ($body->getSize() > 0) {
|
||||
if ($body->isSeekable()) {
|
||||
$data = $body->__toString();
|
||||
$body->rewind();
|
||||
if (preg_match('/[\x00-\x1F\x7F]/', $data)) {
|
||||
$data = '[binary stream omitted]';
|
||||
}
|
||||
} else {
|
||||
$data = '[non-seekable stream omitted]';
|
||||
}
|
||||
$escapedData = @escapeshellarg($data);
|
||||
if (empty($escapedData)) {
|
||||
$escapedData = 'We couldn\'t not escape the data properly';
|
||||
}
|
||||
|
||||
$command .= sprintf(' --data %s', $escapedData);
|
||||
}
|
||||
|
||||
return $command;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function formatResponse(ResponseInterface $response)
|
||||
{
|
||||
return '';
|
||||
}
|
||||
|
||||
/**
|
||||
* @param RequestInterface $request
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
private function getHeadersAsCommandOptions(RequestInterface $request)
|
||||
{
|
||||
$command = '';
|
||||
foreach ($request->getHeaders() as $name => $values) {
|
||||
if ('host' === strtolower($name) && $values[0] === $request->getUri()->getHost()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if ('user-agent' === strtolower($name)) {
|
||||
$command .= sprintf(' -A %s', escapeshellarg($values[0]));
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
$command .= sprintf(' -H %s', escapeshellarg($name.': '.$request->getHeaderLine($name)));
|
||||
}
|
||||
|
||||
return $command;
|
||||
}
|
||||
}
|
||||
91
vendor/php-http/message/src/Formatter/FullHttpMessageFormatter.php
vendored
Normal file
91
vendor/php-http/message/src/Formatter/FullHttpMessageFormatter.php
vendored
Normal file
@@ -0,0 +1,91 @@
|
||||
<?php
|
||||
|
||||
namespace Http\Message\Formatter;
|
||||
|
||||
use Http\Message\Formatter;
|
||||
use Psr\Http\Message\MessageInterface;
|
||||
use Psr\Http\Message\RequestInterface;
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
|
||||
/**
|
||||
* A formatter that prints the complete HTTP message.
|
||||
*
|
||||
* @author Tobias Nyholm <tobias.nyholm@gmail.com>
|
||||
*/
|
||||
class FullHttpMessageFormatter implements Formatter
|
||||
{
|
||||
/**
|
||||
* The maximum length of the body.
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
private $maxBodyLength;
|
||||
|
||||
/**
|
||||
* @param int $maxBodyLength
|
||||
*/
|
||||
public function __construct($maxBodyLength = 1000)
|
||||
{
|
||||
$this->maxBodyLength = $maxBodyLength;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function formatRequest(RequestInterface $request)
|
||||
{
|
||||
$message = sprintf(
|
||||
"%s %s HTTP/%s\n",
|
||||
$request->getMethod(),
|
||||
$request->getRequestTarget(),
|
||||
$request->getProtocolVersion()
|
||||
);
|
||||
|
||||
foreach ($request->getHeaders() as $name => $values) {
|
||||
$message .= $name.': '.implode(', ', $values)."\n";
|
||||
}
|
||||
|
||||
return $this->addBody($request, $message);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function formatResponse(ResponseInterface $response)
|
||||
{
|
||||
$message = sprintf(
|
||||
"HTTP/%s %s %s\n",
|
||||
$response->getProtocolVersion(),
|
||||
$response->getStatusCode(),
|
||||
$response->getReasonPhrase()
|
||||
);
|
||||
|
||||
foreach ($response->getHeaders() as $name => $values) {
|
||||
$message .= $name.': '.implode(', ', $values)."\n";
|
||||
}
|
||||
|
||||
return $this->addBody($response, $message);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add the message body if the stream is seekable.
|
||||
*
|
||||
* @param MessageInterface $request
|
||||
* @param string $message
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
private function addBody(MessageInterface $request, $message)
|
||||
{
|
||||
$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;
|
||||
}
|
||||
}
|
||||
42
vendor/php-http/message/src/Formatter/SimpleFormatter.php
vendored
Normal file
42
vendor/php-http/message/src/Formatter/SimpleFormatter.php
vendored
Normal file
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
|
||||
namespace Http\Message\Formatter;
|
||||
|
||||
use Http\Message\Formatter;
|
||||
use Psr\Http\Message\RequestInterface;
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
|
||||
/**
|
||||
* Normalize a request or a response into a string or an array.
|
||||
*
|
||||
* @author Joel Wurtz <joel.wurtz@gmail.com>
|
||||
* @author Márk Sági-Kazár <mark.sagikazar@gmail.com>
|
||||
*/
|
||||
class SimpleFormatter implements Formatter
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function formatRequest(RequestInterface $request)
|
||||
{
|
||||
return sprintf(
|
||||
'%s %s %s',
|
||||
$request->getMethod(),
|
||||
$request->getUri()->__toString(),
|
||||
$request->getProtocolVersion()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function formatResponse(ResponseInterface $response)
|
||||
{
|
||||
return sprintf(
|
||||
'%s %s %s',
|
||||
$response->getStatusCode(),
|
||||
$response->getReasonPhrase(),
|
||||
$response->getProtocolVersion()
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user