Added support for HTTP compression [#METR-20041].

This commit is contained in:
Alexey Milovidov 2016-02-12 02:37:16 +03:00
parent c7d394f47e
commit 421d5a97ad
4 changed files with 60 additions and 5 deletions

View File

@ -58,7 +58,7 @@ private:
response_ostr = &response.send();
deflating_stream.emplace(*response_ostr, compression_method);
ostr = &deflating_stream;
ostr = &deflating_stream.value();
}
else
{
@ -71,10 +71,10 @@ private:
void nextImpl()
{
sendHeaders();
if (!offset())
return;
ostr->write(working_buffer.begin(), offset());
ostr->flush();

View File

@ -52,9 +52,9 @@ void HTTPHandler::processQuery(Poco::Net::HTTPServerRequest & request, Poco::Net
/** Клиент может указать поддерживаемый метод сжатия (gzip или deflate) в HTTP-заголовке.
*/
String http_compression_methods = request.get("Accept-Encoding");
String http_compression_methods = request.get("Accept-Encoding", "");
bool http_compress = false;
Poco::DeflatingStreamBuf::StreamType http_compression_method;
Poco::DeflatingStreamBuf::StreamType http_compression_method {};
if (!http_compression_methods.empty())
{

View File

@ -0,0 +1,43 @@
0
1
2
3
4
5
6
7
8
9
0
1
2
3
4
5
6
7
8
9
0
1
2
3
4
5
6
7
8
9
0
1
2
3
4
5
6
7
8
9
< Content-Encoding: gzip
< Content-Encoding: deflate
< Content-Encoding: gzip

View File

@ -0,0 +1,12 @@
#!/bin/bash
curl -sS 'http://localhost:8123/' -d 'SELECT number FROM system.numbers LIMIT 10';
curl -sS 'http://localhost:8123/' -H 'Accept-Encoding: gzip' -d 'SELECT number FROM system.numbers LIMIT 10' | gzip -d;
curl -sS 'http://localhost:8123/' -H 'Accept-Encoding: gzip, deflate' -d 'SELECT number FROM system.numbers LIMIT 10' | gzip -d;
curl -sS 'http://localhost:8123/' -H 'Accept-Encoding: zip, eflate' -d 'SELECT number FROM system.numbers LIMIT 10';
curl -vsS 'http://localhost:8123/' -d 'SELECT number FROM system.numbers LIMIT 10' 2>&1 | grep --text '< Content-Encoding';
curl -vsS 'http://localhost:8123/' -H 'Accept-Encoding: gzip' -d 'SELECT number FROM system.numbers LIMIT 10' 2>&1 | grep --text '< Content-Encoding';
curl -vsS 'http://localhost:8123/' -H 'Accept-Encoding: deflate' -d 'SELECT number FROM system.numbers LIMIT 10' 2>&1 | grep --text '< Content-Encoding';
curl -vsS 'http://localhost:8123/' -H 'Accept-Encoding: gzip, deflate' -d 'SELECT number FROM system.numbers LIMIT 10' 2>&1 | grep --text '< Content-Encoding';
curl -vsS 'http://localhost:8123/' -H 'Accept-Encoding: zip, eflate' -d 'SELECT number FROM system.numbers LIMIT 10' 2>&1 | grep --text '< Content-Encoding';