Skip to content

Commit

Permalink
request #14471: Update to guzzle/psr7 1.6.1
Browse files Browse the repository at this point in the history
A change is made to the FileUploadController so the implementation
of the TusServer can continue to work. In guzzle/psr7#247 [0] the default
body of the ServerRequest has been switched to a CachingStream which is
nice until you need to use StreamInterface::detach() because only already
cached data will be available. Forcing data to be put in cache is not interesting
here because we want to save as much as data as possible from the client even
if we only got a part of it (resuming the upload will be dealt with the tus protocol).
To avoid that, we now recreate a StreamInterface directly from the php://input resource
when uploading a file with tus.

[0] guzzle/psr7#247

Change-Id: I167bac3958ffdec37d8b4cf8860d70d73befe3a1
  • Loading branch information
LeSuisse committed Feb 8, 2020
1 parent 3986789 commit 2f5214a
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 18 deletions.
16 changes: 13 additions & 3 deletions src/common/Upload/FileUploadController.php
Expand Up @@ -22,6 +22,7 @@

use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Message\StreamFactoryInterface;
use Psr\Http\Server\MiddlewareInterface;
use Tuleap\Http\HTTPFactoryBuilder;
use Tuleap\Http\Server\SessionWriteCloseMiddleware;
Expand Down Expand Up @@ -49,16 +50,22 @@ final class FileUploadController extends DispatchablePSR15Compatible implements
* @var UserManager
*/
private $user_manager;
/**
* @var StreamFactoryInterface
*/
private $stream_factory;

private function __construct(
TusServer $tus_server,
UserManager $user_manager,
StreamFactoryInterface $stream_factory,
EmitterInterface $emitter,
MiddlewareInterface ...$middleware_stack
) {
parent::__construct($emitter, ...$middleware_stack);
$this->tus_server = $tus_server;
$this->user_manager = $user_manager;
$this->tus_server = $tus_server;
$this->user_manager = $user_manager;
$this->stream_factory = $stream_factory;
}

public static function build(TusDataStore $data_store): self
Expand All @@ -67,6 +74,7 @@ public static function build(TusDataStore $data_store): self
return new self(
new TusServer($response_factory, $data_store),
UserManager::instance(),
HTTPFactoryBuilder::streamFactory(),
new SapiEmitter(),
new SessionWriteCloseMiddleware(),
new RESTCurrentUserMiddleware(\Tuleap\REST\UserManager::build(), new BasicAuthentication()),
Expand All @@ -82,6 +90,8 @@ public function handle(ServerRequestInterface $request) : ResponseInterface
throw new ForbiddenException();
}

return $this->tus_server->handle($request);
return $this->tus_server->handle(
$request->withBody($this->stream_factory->createStreamFromFile('php://input'))
);
}
}
34 changes: 19 additions & 15 deletions src/composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 2f5214a

Please sign in to comment.