Edit File by line
/home/barbar84/public_h.../wp-conte.../plugins/updraftp.../vendor/guzzleht.../guzzle/src
File: PrepareBodyMiddleware.php
<?php
[0] Fix | Delete
namespace GuzzleHttp;
[1] Fix | Delete
[2] Fix | Delete
use GuzzleHttp\Promise\PromiseInterface;
[3] Fix | Delete
use GuzzleHttp\Psr7;
[4] Fix | Delete
use Psr\Http\Message\RequestInterface;
[5] Fix | Delete
[6] Fix | Delete
/**
[7] Fix | Delete
* Prepares requests that contain a body, adding the Content-Length,
[8] Fix | Delete
* Content-Type, and Expect headers.
[9] Fix | Delete
*/
[10] Fix | Delete
class PrepareBodyMiddleware
[11] Fix | Delete
{
[12] Fix | Delete
/** @var callable */
[13] Fix | Delete
private $nextHandler;
[14] Fix | Delete
[15] Fix | Delete
/**
[16] Fix | Delete
* @param callable $nextHandler Next handler to invoke.
[17] Fix | Delete
*/
[18] Fix | Delete
public function __construct(callable $nextHandler)
[19] Fix | Delete
{
[20] Fix | Delete
$this->nextHandler = $nextHandler;
[21] Fix | Delete
}
[22] Fix | Delete
[23] Fix | Delete
/**
[24] Fix | Delete
* @param RequestInterface $request
[25] Fix | Delete
* @param array $options
[26] Fix | Delete
*
[27] Fix | Delete
* @return PromiseInterface
[28] Fix | Delete
*/
[29] Fix | Delete
public function __invoke(RequestInterface $request, array $options)
[30] Fix | Delete
{
[31] Fix | Delete
$fn = $this->nextHandler;
[32] Fix | Delete
[33] Fix | Delete
// Don't do anything if the request has no body.
[34] Fix | Delete
if ($request->getBody()->getSize() === 0) {
[35] Fix | Delete
return $fn($request, $options);
[36] Fix | Delete
}
[37] Fix | Delete
[38] Fix | Delete
$modify = [];
[39] Fix | Delete
[40] Fix | Delete
// Add a default content-type if possible.
[41] Fix | Delete
if (!$request->hasHeader('Content-Type')) {
[42] Fix | Delete
if ($uri = $request->getBody()->getMetadata('uri')) {
[43] Fix | Delete
if ($type = Psr7\mimetype_from_filename($uri)) {
[44] Fix | Delete
$modify['set_headers']['Content-Type'] = $type;
[45] Fix | Delete
}
[46] Fix | Delete
}
[47] Fix | Delete
}
[48] Fix | Delete
[49] Fix | Delete
// Add a default content-length or transfer-encoding header.
[50] Fix | Delete
if (!$request->hasHeader('Content-Length')
[51] Fix | Delete
&& !$request->hasHeader('Transfer-Encoding')
[52] Fix | Delete
) {
[53] Fix | Delete
$size = $request->getBody()->getSize();
[54] Fix | Delete
if ($size !== null) {
[55] Fix | Delete
$modify['set_headers']['Content-Length'] = $size;
[56] Fix | Delete
} else {
[57] Fix | Delete
$modify['set_headers']['Transfer-Encoding'] = 'chunked';
[58] Fix | Delete
}
[59] Fix | Delete
}
[60] Fix | Delete
[61] Fix | Delete
// Add the expect header if needed.
[62] Fix | Delete
$this->addExpectHeader($request, $options, $modify);
[63] Fix | Delete
[64] Fix | Delete
return $fn(Psr7\modify_request($request, $modify), $options);
[65] Fix | Delete
}
[66] Fix | Delete
[67] Fix | Delete
/**
[68] Fix | Delete
* Add expect header
[69] Fix | Delete
*
[70] Fix | Delete
* @return void
[71] Fix | Delete
*/
[72] Fix | Delete
private function addExpectHeader(
[73] Fix | Delete
RequestInterface $request,
[74] Fix | Delete
array $options,
[75] Fix | Delete
array &$modify
[76] Fix | Delete
) {
[77] Fix | Delete
// Determine if the Expect header should be used
[78] Fix | Delete
if ($request->hasHeader('Expect')) {
[79] Fix | Delete
return;
[80] Fix | Delete
}
[81] Fix | Delete
[82] Fix | Delete
$expect = isset($options['expect']) ? $options['expect'] : null;
[83] Fix | Delete
[84] Fix | Delete
// Return if disabled or if you're not using HTTP/1.1 or HTTP/2.0
[85] Fix | Delete
if ($expect === false || $request->getProtocolVersion() < 1.1) {
[86] Fix | Delete
return;
[87] Fix | Delete
}
[88] Fix | Delete
[89] Fix | Delete
// The expect header is unconditionally enabled
[90] Fix | Delete
if ($expect === true) {
[91] Fix | Delete
$modify['set_headers']['Expect'] = '100-Continue';
[92] Fix | Delete
return;
[93] Fix | Delete
}
[94] Fix | Delete
[95] Fix | Delete
// By default, send the expect header when the payload is > 1mb
[96] Fix | Delete
if ($expect === null) {
[97] Fix | Delete
$expect = 1048576;
[98] Fix | Delete
}
[99] Fix | Delete
[100] Fix | Delete
// Always add if the body cannot be rewound, the size cannot be
[101] Fix | Delete
// determined, or the size is greater than the cutoff threshold
[102] Fix | Delete
$body = $request->getBody();
[103] Fix | Delete
$size = $body->getSize();
[104] Fix | Delete
[105] Fix | Delete
if ($size === null || $size >= (int) $expect || !$body->isSeekable()) {
[106] Fix | Delete
$modify['set_headers']['Expect'] = '100-Continue';
[107] Fix | Delete
}
[108] Fix | Delete
}
[109] Fix | Delete
}
[110] Fix | Delete
[111] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function