Skip to content

Commit 0e26e06

Browse files
authored
Enable request support to gzip.
Add support to request to parse gzip encoded posts.
1 parent dae8d63 commit 0e26e06

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

framework/web/Request.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,8 @@ class Request extends \yii\base\Request
307307
* @var HeaderCollection Collection of request headers.
308308
*/
309309
private $_headers;
310+
/** @var boolean Enable gzip inflate */
311+
public $gzip = true;
310312

311313

312314
/**
@@ -569,7 +571,15 @@ public function getIsFlash()
569571
public function getRawBody()
570572
{
571573
if ($this->_rawBody === null) {
572-
$this->_rawBody = file_get_contents('php://input');
574+
$contentEncoding = $this->headers->get('Content-Encoding', '');
575+
if (!empty($contentEncoding)) {
576+
$contentEncoding = strtolower($contentEncoding);
577+
}
578+
if ($this->gzip && $contentEncoding === 'gzip' || $contentEncoding === 'deflate') {
579+
$this->_rawBody = gzinflate(file_get_contents('php://input'));
580+
} else {
581+
$this->_rawBody = file_get_contents('php://input');
582+
}
573583
}
574584

575585
return $this->_rawBody;

0 commit comments

Comments
 (0)