@@ -30,7 +30,7 @@ class HttpTransport implements TransportInterface
3030 protected $ httpClient ;
3131
3232 /**
33- * Array with two keys (read and write ) with guzzle options for corresponding requests.
33+ * Array with three keys (read, write and deflate ) with guzzle options for corresponding requests.
3434 *
3535 * [
3636 * 'read' => [
@@ -41,6 +41,7 @@ class HttpTransport implements TransportInterface
4141 * 'debug' => true,
4242 * 'timeout' => 100,
4343 * ],
44+ * 'deflate' => true
4445 * ]
4546 *
4647 * @var array
@@ -60,17 +61,32 @@ public function __construct(Client $client = null, array $options = [])
6061 $ this ->options = $ options ;
6162 }
6263
64+ /**
65+ * Returns flag to enable / disable queries and data compression
66+ *
67+ * @return bool
68+ */
69+ protected function isDeflateEnabled (): bool
70+ {
71+ return $ this ->options ['deflate ' ] ?? true ;
72+ }
73+
6374 /**
6475 * Returns default headers for requests.
6576 *
6677 * @return array
6778 */
6879 protected function getHeaders ()
6980 {
70- return [
81+ $ headers = [
7182 'Accept-Encoding ' => 'gzip ' ,
72- 'Content-Encoding ' => 'gzip ' ,
7383 ];
84+
85+ if ($ this ->isDeflateEnabled ()) {
86+ $ headers ['Content-Encoding ' ] = 'gzip ' ;
87+ }
88+
89+ return $ headers ;
7490 }
7591
7692 /**
@@ -121,7 +137,7 @@ public function write(array $queries, int $concurrency = 5) : array
121137 'query ' => $ query ->getQuery (),
122138 ], $ query ->getSettings ());
123139
124- $ stream = $ file ->open ();
140+ $ stream = $ file ->open ($ this -> isDeflateEnabled () );
125141 $ openedStreams [] = $ stream ;
126142
127143 $ request = new Request ('POST ' , $ uri , $ headers , $ stream );
@@ -133,7 +149,8 @@ public function write(array $queries, int $concurrency = 5) : array
133149
134150 $ uri = $ this ->buildRequestUri ($ query ->getServer (), [], $ query ->getSettings ());
135151
136- $ request = new Request ('POST ' , $ uri , $ headers , gzencode ($ query ->getQuery ()));
152+ $ sql = $ this ->isDeflateEnabled () ? gzencode ($ query ->getQuery ()) : $ query ->getQuery ();
153+ $ request = new Request ('POST ' , $ uri , $ headers , $ sql );
137154
138155 yield $ request ;
139156 }
0 commit comments