From 4cb8cb55be9b0c7dbf38f4f2333e4701cf8e2fe5 Mon Sep 17 00:00:00 2001 From: Baptiste Langlade Date: Wed, 27 Mar 2024 15:28:20 +0100 Subject: [PATCH 1/4] CS --- src/Factory/Files/FilesFactory.php | 6 +----- src/Factory/Header/AcceptFactory.php | 1 - src/Factory/Header/DelegationFactory.php | 5 +---- src/Factory/Header/HeaderFactory.php | 5 +---- src/Factory/Header/HeadersFactory.php | 1 - src/Header/LinkValue.php | 1 - src/ResponseSender.php | 5 ----- tests/Factory/Files/FilesFactoryTest.php | 4 ---- tests/Factory/Header/FactoriesTest.php | 3 +-- tests/Header/AcceptCharsetTest.php | 1 - tests/Header/AcceptRangesTest.php | 1 - tests/Header/AcceptRangesValueTest.php | 1 - tests/Header/AcceptTest.php | 7 +------ tests/Header/AgeTest.php | 1 - tests/Header/AllowValueTest.php | 1 - tests/Header/AuthorizationTest.php | 1 - tests/Header/CacheControlTest.php | 4 ---- tests/Header/ContentEncodingTest.php | 1 - tests/Header/ContentLengthTest.php | 1 - tests/Header/ContentLocationTest.php | 1 - tests/Header/ContentRangeTest.php | 1 - tests/Header/ContentTypeTest.php | 6 +----- tests/Header/CookieTest.php | 1 - tests/Header/DateTest.php | 1 - tests/Header/ExpiresTest.php | 1 - tests/Header/HostTest.php | 1 - tests/Header/IfModifiedSinceTest.php | 1 - tests/Header/IfUnmodifiedSinceTest.php | 1 - tests/Header/LastModifiedTest.php | 1 - tests/Header/LinkTest.php | 4 ---- tests/Header/LocationTest.php | 1 - tests/Header/RangeTest.php | 1 - tests/Header/ReferrerTest.php | 1 - tests/Header/SetCookieTest.php | 1 - tests/Header/WWWAuthenticateTest.php | 3 +-- tests/HeadersTest.php | 1 - tests/Response/StatusCodeTest.php | 5 +---- tests/ServerRequest/FilesTest.php | 5 +---- 38 files changed, 9 insertions(+), 78 deletions(-) diff --git a/src/Factory/Files/FilesFactory.php b/src/Factory/Files/FilesFactory.php index 4803207..2e21edb 100644 --- a/src/Factory/Files/FilesFactory.php +++ b/src/Factory/Files/FilesFactory.php @@ -7,7 +7,6 @@ Factory\FilesFactory as FilesFactoryInterface, ServerRequest\Files, File\Status, - Exception\LogicException, }; use Innmind\MediaType\MediaType; use Innmind\Filesystem\{ @@ -17,10 +16,7 @@ use Innmind\Url\Path; use Innmind\IO\IO; use Innmind\Stream\Capabilities; -use Innmind\Immutable\{ - Map, - Either, -}; +use Innmind\Immutable\Either; /** * @psalm-immutable diff --git a/src/Factory/Header/AcceptFactory.php b/src/Factory/Header/AcceptFactory.php index 0596624..9eff251 100644 --- a/src/Factory/Header/AcceptFactory.php +++ b/src/Factory/Header/AcceptFactory.php @@ -13,7 +13,6 @@ use Innmind\Immutable\{ Str, Maybe, - Sequence, }; /** diff --git a/src/Factory/Header/DelegationFactory.php b/src/Factory/Header/DelegationFactory.php index 94e6074..afa43f9 100644 --- a/src/Factory/Header/DelegationFactory.php +++ b/src/Factory/Header/DelegationFactory.php @@ -3,10 +3,7 @@ namespace Innmind\Http\Factory\Header; -use Innmind\Http\{ - Factory\HeaderFactory, - Header, -}; +use Innmind\Http\Factory\HeaderFactory; use Innmind\Immutable\{ Map, Str, diff --git a/src/Factory/Header/HeaderFactory.php b/src/Factory/Header/HeaderFactory.php index 0c7381a..631d85a 100644 --- a/src/Factory/Header/HeaderFactory.php +++ b/src/Factory/Header/HeaderFactory.php @@ -7,10 +7,7 @@ Header, Header\Value, }; -use Innmind\Immutable\{ - Str, - Maybe, -}; +use Innmind\Immutable\Str; /** * @psalm-immutable diff --git a/src/Factory/Header/HeadersFactory.php b/src/Factory/Header/HeadersFactory.php index e2396c8..befbe91 100644 --- a/src/Factory/Header/HeadersFactory.php +++ b/src/Factory/Header/HeadersFactory.php @@ -7,7 +7,6 @@ Factory\HeadersFactory as HeadersFactoryInterface, Factory\HeaderFactory as HeaderFactoryInterface, Headers, - Header, }; use Innmind\Immutable\Str; diff --git a/src/Header/LinkValue.php b/src/Header/LinkValue.php index ee399c8..d173fc7 100644 --- a/src/Header/LinkValue.php +++ b/src/Header/LinkValue.php @@ -8,7 +8,6 @@ use Innmind\Immutable\{ Str, Map, - Sequence, Maybe, }; diff --git a/src/ResponseSender.php b/src/ResponseSender.php index 016afb8..b2f7149 100644 --- a/src/ResponseSender.php +++ b/src/ResponseSender.php @@ -5,7 +5,6 @@ use Innmind\Http\{ Header\Date, - Header\DateValue, Header\SetCookie, Header\CookieValue, Header\Parameter, @@ -13,10 +12,6 @@ Exception\LogicException, }; use Innmind\TimeContinuum\Clock; -use Innmind\Immutable\{ - Sequence, - Str, -}; final class ResponseSender implements Sender { diff --git a/tests/Factory/Files/FilesFactoryTest.php b/tests/Factory/Files/FilesFactoryTest.php index a5b7dd4..da8a5e4 100644 --- a/tests/Factory/Files/FilesFactoryTest.php +++ b/tests/Factory/Files/FilesFactoryTest.php @@ -11,10 +11,6 @@ }; use Innmind\IO\IO; use Innmind\Stream\Streams; -use Innmind\Immutable\{ - Map, - MapInterface -}; use PHPUnit\Framework\TestCase; class FilesFactoryTest extends TestCase diff --git a/tests/Factory/Header/FactoriesTest.php b/tests/Factory/Header/FactoriesTest.php index 977f4e9..c529e93 100644 --- a/tests/Factory/Header/FactoriesTest.php +++ b/tests/Factory/Header/FactoriesTest.php @@ -5,8 +5,7 @@ use Innmind\Http\Factory\{ Header\Factories, - Header\DelegationFactory, - HeaderFactory + Header\DelegationFactory }; use Innmind\TimeContinuum\Earth\Clock; use Innmind\Immutable\Map; diff --git a/tests/Header/AcceptCharsetTest.php b/tests/Header/AcceptCharsetTest.php index 29aa38c..c32a0aa 100644 --- a/tests/Header/AcceptCharsetTest.php +++ b/tests/Header/AcceptCharsetTest.php @@ -6,7 +6,6 @@ use Innmind\Http\{ Header\AcceptCharset, Header, - Header\Value, Header\AcceptCharsetValue, Header\Parameter\Quality }; diff --git a/tests/Header/AcceptRangesTest.php b/tests/Header/AcceptRangesTest.php index 0c26d96..cfee1e5 100644 --- a/tests/Header/AcceptRangesTest.php +++ b/tests/Header/AcceptRangesTest.php @@ -6,7 +6,6 @@ use Innmind\Http\{ Header\AcceptRanges, Header, - Header\Value, Header\AcceptRangesValue }; use Innmind\Immutable\Set; diff --git a/tests/Header/AcceptRangesValueTest.php b/tests/Header/AcceptRangesValueTest.php index aca10d0..23fb9f0 100644 --- a/tests/Header/AcceptRangesValueTest.php +++ b/tests/Header/AcceptRangesValueTest.php @@ -6,7 +6,6 @@ use Innmind\Http\{ Header\AcceptRangesValue, Header\Value, - Header\Parameter\Quality, Exception\DomainException, }; use PHPUnit\Framework\TestCase; diff --git a/tests/Header/AcceptTest.php b/tests/Header/AcceptTest.php index ab8ba7f..522cb72 100644 --- a/tests/Header/AcceptTest.php +++ b/tests/Header/AcceptTest.php @@ -7,12 +7,7 @@ Header\Accept, Header, Header\AcceptValue, - Header\Parameter\Quality, - Header\Parameter -}; -use Innmind\Immutable\{ - Set, - Map + Header\Parameter\Quality }; use PHPUnit\Framework\TestCase; diff --git a/tests/Header/AgeTest.php b/tests/Header/AgeTest.php index bd28ab7..fe54663 100644 --- a/tests/Header/AgeTest.php +++ b/tests/Header/AgeTest.php @@ -6,7 +6,6 @@ use Innmind\Http\{ Header\Age, Header, - Header\Value, Header\AgeValue }; use Innmind\Immutable\Set; diff --git a/tests/Header/AllowValueTest.php b/tests/Header/AllowValueTest.php index bc49307..86e1450 100644 --- a/tests/Header/AllowValueTest.php +++ b/tests/Header/AllowValueTest.php @@ -6,7 +6,6 @@ use Innmind\Http\Header\{ AllowValue, Value, - Parameter\Quality, }; use PHPUnit\Framework\TestCase; diff --git a/tests/Header/AuthorizationTest.php b/tests/Header/AuthorizationTest.php index 3c06c20..aaf3ada 100644 --- a/tests/Header/AuthorizationTest.php +++ b/tests/Header/AuthorizationTest.php @@ -6,7 +6,6 @@ use Innmind\Http\{ Header\Authorization, Header, - Header\Value, Header\AuthorizationValue }; use Innmind\Immutable\Set; diff --git a/tests/Header/CacheControlTest.php b/tests/Header/CacheControlTest.php index abd3edd..0b05032 100644 --- a/tests/Header/CacheControlTest.php +++ b/tests/Header/CacheControlTest.php @@ -8,10 +8,6 @@ Header, Header\CacheControlValue\PublicCache }; -use Innmind\Immutable\{ - Set, - Map -}; use PHPUnit\Framework\TestCase; class CacheControlTest extends TestCase diff --git a/tests/Header/ContentEncodingTest.php b/tests/Header/ContentEncodingTest.php index f69b789..b9b6907 100644 --- a/tests/Header/ContentEncodingTest.php +++ b/tests/Header/ContentEncodingTest.php @@ -6,7 +6,6 @@ use Innmind\Http\{ Header\ContentEncoding, Header, - Header\Value, Header\ContentEncodingValue }; use Innmind\Immutable\Set; diff --git a/tests/Header/ContentLengthTest.php b/tests/Header/ContentLengthTest.php index 0c0ee7a..e143416 100644 --- a/tests/Header/ContentLengthTest.php +++ b/tests/Header/ContentLengthTest.php @@ -6,7 +6,6 @@ use Innmind\Http\{ Header\ContentLength, Header, - Header\Value, Header\ContentLengthValue }; use Innmind\Immutable\Set; diff --git a/tests/Header/ContentLocationTest.php b/tests/Header/ContentLocationTest.php index fc44209..d752180 100644 --- a/tests/Header/ContentLocationTest.php +++ b/tests/Header/ContentLocationTest.php @@ -6,7 +6,6 @@ use Innmind\Http\{ Header\ContentLocation, Header, - Header\Value, Header\LocationValue }; use Innmind\Immutable\Set; diff --git a/tests/Header/ContentRangeTest.php b/tests/Header/ContentRangeTest.php index ca9f2a4..6a80527 100644 --- a/tests/Header/ContentRangeTest.php +++ b/tests/Header/ContentRangeTest.php @@ -6,7 +6,6 @@ use Innmind\Http\{ Header\ContentRange, Header, - Header\Value, Header\ContentRangeValue }; use Innmind\Immutable\Set; diff --git a/tests/Header/ContentTypeTest.php b/tests/Header/ContentTypeTest.php index d658871..fa60013 100644 --- a/tests/Header/ContentTypeTest.php +++ b/tests/Header/ContentTypeTest.php @@ -6,14 +6,10 @@ use Innmind\Http\{ Header\ContentType, Header, - Header\Value, Header\ContentTypeValue, Header\Parameter }; -use Innmind\Immutable\{ - Set, - Map, -}; +use Innmind\Immutable\Set; use PHPUnit\Framework\TestCase; class ContentTypeTest extends TestCase diff --git a/tests/Header/CookieTest.php b/tests/Header/CookieTest.php index f9d1841..3288726 100644 --- a/tests/Header/CookieTest.php +++ b/tests/Header/CookieTest.php @@ -6,7 +6,6 @@ use Innmind\Http\{ Header\Cookie, Header, - Header\Value, Header\CookieValue, Header\Parameter\Parameter }; diff --git a/tests/Header/DateTest.php b/tests/Header/DateTest.php index 62249fb..d27afa4 100644 --- a/tests/Header/DateTest.php +++ b/tests/Header/DateTest.php @@ -6,7 +6,6 @@ use Innmind\Http\{ Header\Date, Header, - Header\Value, Header\DateValue }; use Innmind\TimeContinuum\Earth\PointInTime\PointInTime; diff --git a/tests/Header/ExpiresTest.php b/tests/Header/ExpiresTest.php index fd48ee5..49ed09d 100644 --- a/tests/Header/ExpiresTest.php +++ b/tests/Header/ExpiresTest.php @@ -6,7 +6,6 @@ use Innmind\Http\{ Header\Expires, Header, - Header\Value, Header\DateValue }; use Innmind\TimeContinuum\Earth\PointInTime\PointInTime; diff --git a/tests/Header/HostTest.php b/tests/Header/HostTest.php index 8dee469..ebb5fea 100644 --- a/tests/Header/HostTest.php +++ b/tests/Header/HostTest.php @@ -6,7 +6,6 @@ use Innmind\Http\{ Header\Host, Header, - Header\Value, Header\HostValue }; use Innmind\Immutable\Set; diff --git a/tests/Header/IfModifiedSinceTest.php b/tests/Header/IfModifiedSinceTest.php index 90782fe..b5e03d5 100644 --- a/tests/Header/IfModifiedSinceTest.php +++ b/tests/Header/IfModifiedSinceTest.php @@ -6,7 +6,6 @@ use Innmind\Http\{ Header\IfModifiedSince, Header, - Header\Value, Header\DateValue }; use Innmind\TimeContinuum\Earth\PointInTime\PointInTime; diff --git a/tests/Header/IfUnmodifiedSinceTest.php b/tests/Header/IfUnmodifiedSinceTest.php index 7baa3c3..1cb7657 100644 --- a/tests/Header/IfUnmodifiedSinceTest.php +++ b/tests/Header/IfUnmodifiedSinceTest.php @@ -6,7 +6,6 @@ use Innmind\Http\{ Header\IfUnmodifiedSince, Header, - Header\Value, Header\DateValue }; use Innmind\TimeContinuum\Earth\PointInTime\PointInTime; diff --git a/tests/Header/LastModifiedTest.php b/tests/Header/LastModifiedTest.php index 6e7b433..4fc9ae2 100644 --- a/tests/Header/LastModifiedTest.php +++ b/tests/Header/LastModifiedTest.php @@ -6,7 +6,6 @@ use Innmind\Http\{ Header\LastModified, Header, - Header\Value, Header\DateValue }; use Innmind\TimeContinuum\Earth\PointInTime\PointInTime; diff --git a/tests/Header/LinkTest.php b/tests/Header/LinkTest.php index 6b15fd9..b7e0c51 100644 --- a/tests/Header/LinkTest.php +++ b/tests/Header/LinkTest.php @@ -10,10 +10,6 @@ Header\Parameter }; use Innmind\Url\Url; -use Innmind\Immutable\{ - Set, - Map -}; use PHPUnit\Framework\TestCase; class LinkTest extends TestCase diff --git a/tests/Header/LocationTest.php b/tests/Header/LocationTest.php index 658bc6b..6394c4a 100644 --- a/tests/Header/LocationTest.php +++ b/tests/Header/LocationTest.php @@ -6,7 +6,6 @@ use Innmind\Http\{ Header\Location, Header, - Header\Value, Header\LocationValue }; use Innmind\Immutable\Set; diff --git a/tests/Header/RangeTest.php b/tests/Header/RangeTest.php index ec6be2f..3bd8cdf 100644 --- a/tests/Header/RangeTest.php +++ b/tests/Header/RangeTest.php @@ -6,7 +6,6 @@ use Innmind\Http\{ Header\Range, Header, - Header\Value, Header\RangeValue }; use Innmind\Immutable\Set; diff --git a/tests/Header/ReferrerTest.php b/tests/Header/ReferrerTest.php index c925b5d..88d6dad 100644 --- a/tests/Header/ReferrerTest.php +++ b/tests/Header/ReferrerTest.php @@ -6,7 +6,6 @@ use Innmind\Http\{ Header\Referrer, Header, - Header\Value, Header\ReferrerValue }; use Innmind\Immutable\Set; diff --git a/tests/Header/SetCookieTest.php b/tests/Header/SetCookieTest.php index 876d55f..1bbbde7 100644 --- a/tests/Header/SetCookieTest.php +++ b/tests/Header/SetCookieTest.php @@ -6,7 +6,6 @@ use Innmind\Http\{ Header\SetCookie, Header, - Header\Value, Header\CookieValue, Header\Parameter\Parameter, Header\CookieParameter\Secure diff --git a/tests/Header/WWWAuthenticateTest.php b/tests/Header/WWWAuthenticateTest.php index a4cb7da..9bae33f 100644 --- a/tests/Header/WWWAuthenticateTest.php +++ b/tests/Header/WWWAuthenticateTest.php @@ -6,8 +6,7 @@ use Innmind\Http\{ Header\WWWAuthenticate, Header\WWWAuthenticateValue, - Header, - Header\Value + Header }; use Innmind\Immutable\Set; use PHPUnit\Framework\TestCase; diff --git a/tests/HeadersTest.php b/tests/HeadersTest.php index 14399d5..6db3313 100644 --- a/tests/HeadersTest.php +++ b/tests/HeadersTest.php @@ -10,7 +10,6 @@ Header\Allow, Header\ContentType, Header\ContentTypeValue, - Header\Parameter, Header\Value\Value, }; use Innmind\Immutable\SideEffect; diff --git a/tests/Response/StatusCodeTest.php b/tests/Response/StatusCodeTest.php index aeda0ff..f1dc0c6 100644 --- a/tests/Response/StatusCodeTest.php +++ b/tests/Response/StatusCodeTest.php @@ -5,10 +5,7 @@ use Innmind\Http\Response\StatusCode; use PHPUnit\Framework\TestCase; -use Innmind\BlackBox\{ - PHPUnit\BlackBox, - Set, -}; +use Innmind\BlackBox\PHPUnit\BlackBox; class StatusCodeTest extends TestCase { diff --git a/tests/ServerRequest/FilesTest.php b/tests/ServerRequest/FilesTest.php index 2a45412..c4c13de 100644 --- a/tests/ServerRequest/FilesTest.php +++ b/tests/ServerRequest/FilesTest.php @@ -8,10 +8,7 @@ File\Status, }; use Innmind\Filesystem\File; -use Innmind\Immutable\{ - Map, - Either, -}; +use Innmind\Immutable\Either; use PHPUnit\Framework\TestCase; class FilesTest extends TestCase From d3b72bb863f8c0708cbf8b418697ca58ff6a914a Mon Sep 17 00:00:00 2001 From: Baptiste Langlade Date: Wed, 27 Mar 2024 15:31:45 +0100 Subject: [PATCH 2/4] fix psalm error --- src/ResponseSender.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/ResponseSender.php b/src/ResponseSender.php index b2f7149..28510f7 100644 --- a/src/ResponseSender.php +++ b/src/ResponseSender.php @@ -89,7 +89,10 @@ static function(array $parameters, Parameter $parameter): array { )->getTimestamp(); // MaxAge has precedence /** @psalm-suppress MixedAssignment */ - $parameters['expire'] = ($parameters['expire'] ?? 0 !== 0) ? $parameters['expire'] : $timestamp; + $parameters['expire'] = match ($parameters['expire'] ?? 0) { + 0 => $timestamp, + default => $parameters['expire'] ?? 0, + }; break; case 'Max-Age': From 18f6d4b561a1aecf47206b4d82e650b61c51b952 Mon Sep 17 00:00:00 2001 From: Baptiste Langlade Date: Wed, 27 Mar 2024 15:34:19 +0100 Subject: [PATCH 3/4] fix loading the multipart files in memory --- CHANGELOG.md | 6 ++++++ src/Content/Multipart/File.php | 4 +++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index bf0cf4f..0190135 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ # Changelog +## [Unreleased] + +### Fixed + +- Files used in `Innmind\Http\Content\Multipart` are no longer loaded in memory + ## 7.0.0 - 2023-10-22 ### Changed diff --git a/src/Content/Multipart/File.php b/src/Content/Multipart/File.php index b7e1e21..afb0855 100644 --- a/src/Content/Multipart/File.php +++ b/src/Content/Multipart/File.php @@ -61,7 +61,9 @@ private function headers(): Sequence { $name = $this->file->name()->toString(); $mediaType = $this->file->mediaType()->toString(); - $headers = Sequence::of( + // Use a lazy Sequence here to prevent loading the whole file in memory + // when the the chunks are appended to the headers in self::chunks() + $headers = Sequence::lazyStartingWith( Str::of("Content-Disposition: form-data; name=\"{$this->name}\"; filename=\"$name\"\r\n"), Str::of("Content-Type: $mediaType\r\n"), ); From 7d2e0fca8c4077a2a4991282e61b46d0c7b57063 Mon Sep 17 00:00:00 2001 From: Baptiste Langlade Date: Wed, 27 Mar 2024 15:45:23 +0100 Subject: [PATCH 4/4] specify next release --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0190135..1e91676 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,6 @@ # Changelog -## [Unreleased] +## 7.0.1 - 2024-03-27 ### Fixed