-
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, | ||
|
||
); | ||
} | ||
|
||
|
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); | ||
|
||
} | ||
|
||
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'); | ||
|
||
} | ||
|
||
$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.
Outdated
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.