diff options
author | Robin Appelman <robin@icewind.nl> | 2016-10-28 16:35:39 +0200 |
---|---|---|
committer | Robin Appelman <robin@icewind.nl> | 2016-11-16 15:30:37 +0100 |
commit | 3ab160dd5a9071bb993fe95361d29f1f8d74ab93 (patch) | |
tree | 46addffd1b45b08daea8a4d6978f8a8d6add366e /lib/private/Files/ObjectStore | |
parent | eb21dc2bd33040882eac52e3a768963f20ac3b4a (diff) | |
download | nextcloud-server-3ab160dd5a9071bb993fe95361d29f1f8d74ab93.tar.gz nextcloud-server-3ab160dd5a9071bb993fe95361d29f1f8d74ab93.zip |
fopen s3 objects directly to work around unexplainable guzzle bug
For some reason when a text file started with a valid hex character ([0-9a-f]) it would eat the text untill the first newline
The new code does basically the same thing as guzzle/s3-sdk did only without wrapping everything in a guzzle stream
Signed-off-by: Robin Appelman <robin@icewind.nl>
Diffstat (limited to 'lib/private/Files/ObjectStore')
-rw-r--r-- | lib/private/Files/ObjectStore/S3.php | 51 |
1 files changed, 21 insertions, 30 deletions
diff --git a/lib/private/Files/ObjectStore/S3.php b/lib/private/Files/ObjectStore/S3.php index 641c1722b58..5251b473bdf 100644 --- a/lib/private/Files/ObjectStore/S3.php +++ b/lib/private/Files/ObjectStore/S3.php @@ -21,11 +21,6 @@ namespace OC\Files\ObjectStore; -use Guzzle\Http\EntityBody; -use Guzzle\Http\Message\RequestInterface; -use Guzzle\Service\Command\CommandInterface; -use Guzzle\Stream\PhpStreamRequestFactory; -use Icewind\Streams\CallbackWrapper; use OCP\Files\ObjectStore\IObjectStore; // TODO: proper composer @@ -49,20 +44,6 @@ class S3 implements IObjectStore { } /** - * Serialize and sign a command, returning a request object - * - * @param CommandInterface $command Command to sign - * - * @return RequestInterface - */ - protected function getSignedRequest($command) { - $request = $command->prepare(); - $request->dispatch('request.before_send', array('request' => $request)); - - return $request; - } - - /** * @param string $urn the unified resource name used to identify the object * @return resource stream with the read data * @throws \Exception when something goes wrong, message will be logged @@ -70,20 +51,30 @@ class S3 implements IObjectStore { */ function readObject($urn) { // Create the command and serialize the request - $request = $this->getSignedRequest($this->getConnection()->getCommand('GetObject', [ + $request = $this->getConnection()->getCommand('GetObject', [ 'Bucket' => $this->bucket, 'Key' => $urn - ])); - // Create a stream that uses the EntityBody object - $factory = new PhpStreamRequestFactory(); - /** @var EntityBody $body */ - $body = $factory->fromRequest($request, array(), array('stream_class' => 'Guzzle\Http\EntityBody')); - $stream = $body->getStream(); + ])->prepare(); + + $request->dispatch('request.before_send', array( + 'request' => $request + )); + + $headers = $request->getHeaderLines(); + $headers[] = 'Connection: close'; + + $opts = [ + 'http' => [ + 'method' => "GET", + 'header' => $headers + ], + 'ssl' => [ + 'verify_peer' => true + ] + ]; - // we need to keep the guzzle request in scope untill the stream is closed - return CallbackWrapper::wrap($stream, null, null, function () use ($body) { - $body->close(); - }); + $context = stream_context_create($opts); + return fopen($request->getUrl(), 'r', false, $context); } /** |