-
Notifications
You must be signed in to change notification settings - Fork 113
Addition of gzip feature #568
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: v3
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,6 +29,7 @@ public function getDefaultConfig() | |
'defaultHeaders' => array(), | ||
'defaultForwardToReplicas' => null, | ||
'batchSize' => 1000, | ||
'gzipEnabled' => true, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a good point, @chloelbn you may need to refactor the pull request in order to prepare the PHP client for other compression types. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Don't hesitate on syncing with me for tackling this refactorization. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done in the last commit, what are your thoughts? |
||
); | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -62,6 +62,10 @@ public function __construct( | |
$this->updateHostFromUri(); | ||
} | ||
|
||
if ($this->hasHeader('Content-Encoding')) { | ||
$body = gzencode($body, 9); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's double check the level here, we are not sure if There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's unit test this to make sure we have this header in both requests, maybe is already the case. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. tests added, as for compression 9 is the higher level but I guess it will take more time. Not sure how to benchmark which level to use |
||
} | ||
|
||
if ('' !== $body && null !== $body) { | ||
$this->stream = stream_for($body); | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -111,6 +111,10 @@ public function send($method, $path, $requestOptions = array(), $hosts = null) | |
|
||
private function request($method, $path, RequestOptions $requestOptions, $hosts, $timeout, $data = array()) | ||
{ | ||
if ($this->canEnableGzipCompress($method)) { | ||
$requestOptions->addHeader('Content-Encoding', 'gzip'); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is the underlying HTTP library computing the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @chloelbn Seems like tests are still failing, is the underlying http library setting this header? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Or, the |
||
} | ||
|
||
$uri = $this->createUri($path) | ||
->withQuery($requestOptions->getBuiltQueryParameters()) | ||
->withScheme('https'); | ||
|
@@ -215,6 +219,14 @@ private function createUri($uri) | |
throw new \InvalidArgumentException('URI must be a string or UriInterface'); | ||
} | ||
|
||
/** | ||
chloelbn marked this conversation as resolved.
Show resolved
Hide resolved
|
||
* @param $method | ||
* @param $uri | ||
* @param array $headers | ||
* @param null $body | ||
* @param string $protocolVersion | ||
* @return Request | ||
*/ | ||
private function createRequest( | ||
$method, | ||
$uri, | ||
|
@@ -239,6 +251,12 @@ private function createRequest( | |
return new Request($method, $uri, $headers, $body, $protocolVersion); | ||
} | ||
|
||
private function canEnableGzipCompress($method) | ||
{ | ||
return (strtoupper($method) === 'POST' || strtoupper($method) === 'PUT') | ||
chloelbn marked this conversation as resolved.
Show resolved
Hide resolved
|
||
&& $this->config->getGzipEnabled(); | ||
} | ||
|
||
/** | ||
* @param string $level | ||
* @param string $message | ||
|
Uh oh!
There was an error while loading. Please reload this page.