private function addExpectHeader(RequestInterface $request, StreamInterface $body) { // Determine if the Expect header should be used if ($request->hasHeader('Expect')) { return; } $expect = $request->getConfig()['expect']; // Return if disabled or if you're not using HTTP/1.1 if ($expect === false || $request->getProtocolVersion() !== '1.1') { return; } // The expect header is unconditionally enabled if ($expect === true) { $request->setHeader('Expect', '100-Continue'); return; } // By default, send the expect header when the payload is > 1mb if ($expect === null) { $expect = 1048576; } // Always add if the body cannot be rewound, the size cannot be // determined, or the size is greater than the cutoff threshold $size = $body->getSize(); if ($size === null || $size >= (int) $expect || !$body->isSeekable()) { $request->setHeader('Expect', '100-Continue'); } }
/** * {@inheritdoc} */ protected function doGetSize() { return $this->stream->getSize(); }
public function getSize() { return $this->stream->getSize(); }
/** * Determines if the body should be uploaded using PutObject or the * Multipart Upload System. It also modifies the passed-in $body as needed * to support the upload. * * @param StreamInterface $body Stream representing the body. * @param integer $threshold Minimum bytes before using Multipart. * * @return bool */ private function requiresMultipart(StreamInterface &$body, $threshold) { // If body size known, compare to threshold to determine if Multipart. if ($body->getSize() !== null) { return $body->getSize() < $threshold ? false : true; } // Handle the situation where the body size is unknown. // Read up to 5MB into a buffer to determine how to upload the body. $buffer = Stream::factory(); Utils::copyToStream($body, $buffer, 5242880); // If body < 5MB, use PutObject with the buffer. if ($buffer->getSize() < 5242880) { $buffer->seek(0); $body = $buffer; return false; } // If >= 5 MB, and seekable, use Multipart with rewound body. if ($body->isSeekable()) { $body->seek(0); return true; } // If >= 5 MB, and non-seekable, use Multipart, but stitch the // buffer and the body together into one stream. This avoids // needing to seek and unnecessary disc usage, while requiring // only the 5 MB buffer to be re-read by the Multipart system. $buffer->seek(0); $body = new AppendStream([$buffer, $body]); return true; }