-
-
Notifications
You must be signed in to change notification settings - Fork 6.9k
Enable request support to gzip. #20477
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
base: master
Are you sure you want to change the base?
Conversation
Add support to request to parse gzip encoded posts.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #20477 +/- ##
=========================================
Coverage 64.47% 64.47%
- Complexity 11574 11579 +5
=========================================
Files 433 433
Lines 37598 37606 +8
=========================================
+ Hits 24240 24248 +8
Misses 13358 13358 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Thanks for the PR, to avoid creating BC, i left the gzip option set to |
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.
Looks good. Please add a line for CHANGELOG. Also, is it possible to add some unit tests for it?
@samdark @terabytesoftw Tests included. Still there is a scenario left. |
@lucaswitch how did you encounter the issue this pull request is solving btw.? Which server was it? Majority of servers are decoding gzip transparently and automatically. |
They do handle it but on the responses. When incoming requests are done with Content-Encoding: gzip it leaves for the app to handle the encoding processing. |
In my particular case i'm uploading huge json payloads, my mobile device works as offline first, so it could be that the next time the device has internet it needs to post huge json changes, but this json can be hugely compressed by using gzip as the values can repeat(mostly embedded devices voltages data that repeat a lot). Would be awesome if Yii2 and Yii3 could support decoding that on application level. |
Why this option is called |
Just by convention, since gzip/deflate are the most commonly used, but perhaps a better name would be $zLibDecode or $contentEncodingDecompress , although it’s less familiar to new users. Also i would not support a compressing algorithm that php don't support. |
Maybe the naming would be better as: $request = new Request(['useContentEncoding' => true]); |
How about |
How about creating something like |
according to @rob006 a separate component would allow to solve the task completely. |
Agreed! I guess we can use something like a new RequestRawBodyDecoderInterface that would work just like RequestParserInterface. in web.php [
// ... web
'request'=> [
'rawBodyDecoders' => [
'gzip' => GZipDecoder::class, // we can have that by default cause it's supported by php zlib by default
'deflate' => DeflateDecoder::class, // we can have that by default cause it's supported by php zlib by default
'br' => function ($rawBody) { // callable a new class extends RequestDecoderInterface
return $rawBody; // process it to after parsers deal with it
}
//
]
]
] in that way we can reuse it outside of http headers scenarios in some controller $uploadedImage = UploadedFile::getInstance($model, 'compressed_image');
$gzipDecoder = new GZipDecoder();
$binary = $gzipDecoder->parse(file_get_contents($uploadedImage->tempName)); Should i modify this pull request to add it? |
Today we can handle a single request like following, or every request by extending the request class // manually check the headers then
gzdecode(Yii::$app->request->getRawBody()); |
I was thinking about single component that would take headers and raw body and handle everything internally. It would not be |
Got 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.
lgtm
Add support to request to parse gzip encoded posts.