Skip to content
This repository has been archived by the owner on Feb 5, 2019. It is now read-only.

Commit

Permalink
automatically adding stream sizes
Browse files Browse the repository at this point in the history
  • Loading branch information
Joan Fabrégat committed Mar 4, 2018
1 parent d2c140a commit 8f23ca7
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "codeinchq/lib-psr7responses",
"version": "1.1.4",
"version": "1.1.5",
"description": "A collection of PSR-7 responses",
"homepage": "https://github.com/codeinchq/lib-psr7responses",
"type": "library",
Expand Down
5 changes: 4 additions & 1 deletion src/StreamResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,17 @@ public function __construct($resource, ?string $mimeType = null, ?int $contentLe
?string $fileName = null, bool $asAttachment = false, int $status = 200, array $headers = [],
string $version = '1.1', ?string $reason = null)
{
$stream = stream_for($resource);

// adding headers
if ($mimeType) {
$headers["Content-Type"] = $mimeType;
}
$headers["Content-Disposition"] = $asAttachment ? "attachment" : "inline";
if ($fileName) {
$headers["Content-Disposition"] .= sprintf("; filename=\"%s\"", $fileName);
}
if ($contentLength !== null) {
if ($contentLength !== null || ($contentLength = $stream->getSize()) !== null) {
$headers["Content-Length"] = $contentLength;
}

Expand Down

0 comments on commit 8f23ca7

Please sign in to comment.