-
-
Notifications
You must be signed in to change notification settings - Fork 145
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support buffering request body (RequestBodyBufferMiddleware) #216
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice, would love to get this in! My main concern with this PR is lack of documentation, looks like some of this somehow ended up in #215 instead?
tests/Middleware/BufferTest.php
Outdated
public function testToLargeBody() | ||
{ | ||
$size = $this->iniMaxPostSize() + 1; | ||
$stream = new BufferStream($size); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure what's supposed to be tested here? Afaict this should probably use a fixed limit instead?
src/Middleware/Buffer.php
Outdated
|
||
if ($size === null) { | ||
return new Response(411, array('Content-Type' => 'text/plain'), 'No Content-Length header given'); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes perfect sense to me, but we should probably add some documentation and tests for this 👍
For the reference: I've discussed this with @WyriHaximus and I think it's save to say we all agree that it may make sense to also support incoming requests with Transfer-Encoding: chunked
in a future version (follow-up PR) 👍 This feature is rarely used in the real world and not something that will be needed for most people (unlike outgoing responses with Transfer-Encoding: chunked
which are supported).
src/Middleware/Buffer.php
Outdated
{ | ||
private $sizeLimit; | ||
|
||
public function __construct($sizeLimit = null) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could use some documentation about the expected parameter type 👍
src/Middleware/Buffer.php
Outdated
use React\Stream\ReadableStreamInterface; | ||
use RingCentral\Psr7\BufferStream; | ||
|
||
final class Buffer |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure about the name, as new Buffer()
doesn't really convey its responsibility? How about something like RequestBufferer
(which doesn't sound perfect either).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
RequestBodyBuffer
could work.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1 for RequestBodyBuffer
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds much better to me, so I won't block this 👍
To be this name still implies this class represents the buffer itself, while it is actually (only) responsible for the buffering process and storing the complete buffer back into the request instance that will be passed upstream.
I guess this class could use some documentation? :-)
src/Middleware/RequestBodyBuffer.php
Outdated
{ | ||
private $sizeLimit; | ||
|
||
public function __construct($sizeLimit = null) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could use some documentation about the expected parameter type 👍
public function testToLargeBody() | ||
{ | ||
$size = $this->iniMaxPostSize() + 1; | ||
$stream = new BufferStream($size); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure what's supposed to be tested here? Afaict this should probably use a fixed limit instead?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Replaced that tests with one specifically for the 413 error
src/Middleware/RequestBodyBuffer.php
Outdated
|
||
if ($size === null) { | ||
return new Response(411, array('Content-Type' => 'text/plain'), 'No Content-Length header given'); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes perfect sense to me, but we should probably add some documentation and tests for this 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added a test for it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And added docs for it
src/Middleware/RequestBodyBuffer.php
Outdated
@@ -61,6 +77,6 @@ private function iniMaxPostSize() | |||
return substr($size, 0, -1) * 1024 * 1024 * 1024; | |||
} | |||
|
|||
return $size; | |||
throw new \UnexpectedValueException('post_max_size value is out of range.'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will now throw for a size specified in bytes (without a suffix)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point, I've reverted it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated the PR title with the correct class name.
Thanks! Ping @clue :P |
949b061
to
0bbc802
Compare
0bbc802
to
4c4e950
Compare
4c4e950
to
c8d66b8
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice! 🎉 I've rebased and squashed some of your changes and updated the documentation to describe streaming<->buffered request handling, otherwise looks good to me functionally 👍 If you're okay with my changes, let's get this in!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cool, changes look good 👍
Buffer Middleware split off from #213
Assumes to be used with #215