Skip to content
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

Merged
merged 4 commits into from
Sep 11, 2017

Conversation

WyriHaximus
Copy link
Member

@WyriHaximus WyriHaximus commented Sep 6, 2017

Buffer Middleware split off from #213
Assumes to be used with #215

Copy link
Member

@clue clue left a 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! :shipit: My main concern with this PR is lack of documentation, looks like some of this somehow ended up in #215 instead?

public function testToLargeBody()
{
$size = $this->iniMaxPostSize() + 1;
$stream = new BufferStream($size);
Copy link
Member

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?


if ($size === null) {
return new Response(411, array('Content-Type' => 'text/plain'), 'No Content-Length header given');
}
Copy link
Member

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).

{
private $sizeLimit;

public function __construct($sizeLimit = null)
Copy link
Member

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 👍

use React\Stream\ReadableStreamInterface;
use RingCentral\Psr7\BufferStream;

final class Buffer
Copy link
Member

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).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

RequestBodyBuffer could work.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1 for RequestBodyBuffer.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

Copy link
Member

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? :-)

@WyriHaximus
Copy link
Member Author

@clue yes it ended up in #215 by accident, once that is in I'll update this PR with that bit of documentation 👍

{
private $sizeLimit;

public function __construct($sizeLimit = null)
Copy link
Member

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);
Copy link
Member

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?

Copy link
Member Author

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


if ($size === null) {
return new Response(411, array('Content-Type' => 'text/plain'), 'No Content-Length header given');
}
Copy link
Member

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 👍

Copy link
Member Author

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

Copy link
Member Author

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

@@ -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.');
Copy link
Member

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)

Copy link
Member Author

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

@WyriHaximus
Copy link
Member Author

@jsor @clue updated the PR with your feedback 👍

@clue clue removed the easy pick label Sep 10, 2017
@jsor jsor changed the title Buffer Middleware RequestBodyBuffer Middleware Sep 10, 2017
Copy link
Member

@jsor jsor left a 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.

@WyriHaximus
Copy link
Member Author

Thanks! Ping @clue :P

@clue clue force-pushed the middleware-buffer branch from 0bbc802 to 4c4e950 Compare September 11, 2017 17:12
@clue clue force-pushed the middleware-buffer branch from 4c4e950 to c8d66b8 Compare September 11, 2017 17:16
Copy link
Member

@clue clue left a 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! :shipit:

@clue clue changed the title RequestBodyBuffer Middleware Support buffering request body (RequestBodyBufferMiddleware) Sep 11, 2017
Copy link
Member Author

@WyriHaximus WyriHaximus left a 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 👍

@WyriHaximus WyriHaximus merged commit abdf36e into reactphp:master Sep 11, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants