From c762dbea7738685745f8122a9dfe462fe334f759 Mon Sep 17 00:00:00 2001 From: facedsid Date: Tue, 14 Jul 2020 12:03:57 +0300 Subject: [PATCH] added ability to enable / disable deflate filter on write queries --- src/Transport/HttpTransport.php | 27 ++++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/src/Transport/HttpTransport.php b/src/Transport/HttpTransport.php index 44da08d..3baa82d 100644 --- a/src/Transport/HttpTransport.php +++ b/src/Transport/HttpTransport.php @@ -30,7 +30,7 @@ class HttpTransport implements TransportInterface protected $httpClient; /** - * Array with two keys (read and write) with guzzle options for corresponding requests. + * Array with three keys (read, write and deflate) with guzzle options for corresponding requests. * * [ * 'read' => [ @@ -41,6 +41,7 @@ class HttpTransport implements TransportInterface * 'debug' => true, * 'timeout' => 100, * ], + * 'deflate' => true * ] * * @var array @@ -60,6 +61,16 @@ public function __construct(Client $client = null, array $options = []) $this->options = $options; } + /** + * Returns flag to enable / disable queries and data compression + * + * @return bool + */ + protected function isDeflateEnabled(): bool + { + return $this->options['deflate'] ?? true; + } + /** * Returns default headers for requests. * @@ -67,10 +78,15 @@ public function __construct(Client $client = null, array $options = []) */ protected function getHeaders() { - return [ + $headers = [ 'Accept-Encoding' => 'gzip', - 'Content-Encoding' => 'gzip', ]; + + if ($this->isDeflateEnabled()) { + $headers['Content-Encoding'] = 'gzip'; + } + + return $headers; } /** @@ -121,7 +137,7 @@ public function write(array $queries, int $concurrency = 5) : array 'query' => $query->getQuery(), ], $query->getSettings()); - $stream = $file->open(); + $stream = $file->open($this->isDeflateEnabled()); $openedStreams[] = $stream; $request = new Request('POST', $uri, $headers, $stream); @@ -133,7 +149,8 @@ public function write(array $queries, int $concurrency = 5) : array $uri = $this->buildRequestUri($query->getServer(), [], $query->getSettings()); - $request = new Request('POST', $uri, $headers, gzencode($query->getQuery())); + $sql = $this->isDeflateEnabled() ? gzencode($query->getQuery()) : $query->getQuery(); + $request = new Request('POST', $uri, $headers, $sql); yield $request; }