Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
2dot5
ClickHouse
提交
5c8c9907
C
ClickHouse
项目概览
2dot5
/
ClickHouse
通知
3
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
C
ClickHouse
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
5c8c9907
编写于
1月 05, 2020
作者:
A
Alexey Milovidov
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Fixed error
上级
a0182605
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
53 addition
and
37 deletion
+53
-37
dbms/programs/server/HTTPHandler.cpp
dbms/programs/server/HTTPHandler.cpp
+5
-13
dbms/src/IO/CompressionMethod.cpp
dbms/src/IO/CompressionMethod.cpp
+17
-6
dbms/src/IO/CompressionMethod.h
dbms/src/IO/CompressionMethod.h
+18
-4
dbms/src/IO/WriteBufferFromHTTPServerResponse.cpp
dbms/src/IO/WriteBufferFromHTTPServerResponse.cpp
+10
-12
dbms/src/IO/WriteBufferFromHTTPServerResponse.h
dbms/src/IO/WriteBufferFromHTTPServerResponse.h
+3
-2
未找到文件。
dbms/programs/server/HTTPHandler.cpp
浏览文件 @
5c8c9907
...
...
@@ -298,30 +298,22 @@ void HTTPHandler::processQuery(
/// The client can pass a HTTP header indicating supported compression method (gzip or deflate).
String
http_response_compression_methods
=
request
.
get
(
"Accept-Encoding"
,
""
);
bool
client_supports_http_compression
=
false
;
CompressionMethod
http_response_compression_method
{};
CompressionMethod
http_response_compression_method
=
CompressionMethod
::
None
;
if
(
!
http_response_compression_methods
.
empty
())
{
/// Both gzip and deflate are supported. If the client supports both, gzip is preferred.
/// NOTE parsing of the list of methods is slightly incorrect.
if
(
std
::
string
::
npos
!=
http_response_compression_methods
.
find
(
"gzip"
))
{
client_supports_http_compression
=
true
;
http_response_compression_method
=
CompressionMethod
::
Gzip
;
}
else
if
(
std
::
string
::
npos
!=
http_response_compression_methods
.
find
(
"deflate"
))
{
client_supports_http_compression
=
true
;
http_response_compression_method
=
CompressionMethod
::
Zlib
;
}
else
if
(
http_response_compression_methods
==
"br"
)
{
client_supports_http_compression
=
true
;
http_response_compression_method
=
CompressionMethod
::
Brotli
;
}
}
bool
client_supports_http_compression
=
http_response_compression_method
!=
CompressionMethod
::
None
;
/// Client can pass a 'compress' flag in the query string. In this case the query result is
/// compressed using internal algorithm. This is not reflected in HTTP headers.
bool
internal_compression
=
params
.
getParsed
<
bool
>
(
"compress"
,
false
);
...
...
@@ -340,8 +332,8 @@ void HTTPHandler::processQuery(
unsigned
keep_alive_timeout
=
config
.
getUInt
(
"keep_alive_timeout"
,
10
);
used_output
.
out
=
std
::
make_shared
<
WriteBufferFromHTTPServerResponse
>
(
request
,
response
,
keep_alive_timeout
,
client_supports_http_compression
,
http_response_compression_method
);
request
,
response
,
keep_alive_timeout
,
client_supports_http_compression
,
http_response_compression_method
);
if
(
internal_compression
)
used_output
.
out_maybe_compressed
=
std
::
make_shared
<
CompressedWriteBuffer
>
(
*
used_output
.
out
);
else
...
...
dbms/src/IO/CompressionMethod.cpp
浏览文件 @
5c8c9907
...
...
@@ -58,13 +58,18 @@ CompressionMethod chooseCompressionMethod(const std::string & path, const std::s
}
std
::
unique_ptr
<
ReadBuffer
>
wrapReadBufferWithCompressionMethod
(
std
::
unique_ptr
<
ReadBuffer
>
nested
,
CompressionMethod
method
)
std
::
unique_ptr
<
ReadBuffer
>
wrapReadBufferWithCompressionMethod
(
std
::
unique_ptr
<
ReadBuffer
>
nested
,
CompressionMethod
method
,
size_t
buf_size
,
char
*
existing_memory
,
size_t
alignment
)
{
if
(
method
==
CompressionMethod
::
Gzip
||
method
==
CompressionMethod
::
Zlib
)
return
std
::
make_unique
<
ZlibInflatingReadBuffer
>
(
std
::
move
(
nested
),
method
);
return
std
::
make_unique
<
ZlibInflatingReadBuffer
>
(
std
::
move
(
nested
),
method
,
buf_size
,
existing_memory
,
alignment
);
#if USE_BROTLI
if
(
method
==
CompressionMethod
::
Brotli
)
return
std
::
make_unique
<
BrotliReadBuffer
>
(
std
::
move
(
nested
));
return
std
::
make_unique
<
BrotliReadBuffer
>
(
std
::
move
(
nested
)
,
buf_size
,
existing_memory
,
alignment
);
#endif
if
(
method
==
CompressionMethod
::
None
)
...
...
@@ -74,14 +79,20 @@ std::unique_ptr<ReadBuffer> wrapReadBufferWithCompressionMethod(std::unique_ptr<
}
std
::
unique_ptr
<
WriteBuffer
>
wrapWriteBufferWithCompressionMethod
(
std
::
unique_ptr
<
WriteBuffer
>
nested
,
CompressionMethod
method
,
int
level
)
std
::
unique_ptr
<
WriteBuffer
>
wrapWriteBufferWithCompressionMethod
(
std
::
unique_ptr
<
WriteBuffer
>
nested
,
CompressionMethod
method
,
int
level
,
size_t
buf_size
,
char
*
existing_memory
,
size_t
alignment
)
{
if
(
method
==
DB
::
CompressionMethod
::
Gzip
||
method
==
CompressionMethod
::
Zlib
)
return
std
::
make_unique
<
ZlibDeflatingWriteBuffer
>
(
std
::
move
(
nested
),
method
,
level
);
return
std
::
make_unique
<
ZlibDeflatingWriteBuffer
>
(
std
::
move
(
nested
),
method
,
level
,
buf_size
,
existing_memory
,
alignment
);
#if USE_BROTLI
if
(
method
==
DB
::
CompressionMethod
::
Brotli
)
return
std
::
make_unique
<
BrotliWriteBuffer
>
(
std
::
move
(
nested
),
level
);
return
std
::
make_unique
<
BrotliWriteBuffer
>
(
std
::
move
(
nested
),
level
,
buf_size
,
existing_memory
,
alignment
);
#endif
if
(
method
==
CompressionMethod
::
None
)
...
...
dbms/src/IO/CompressionMethod.h
浏览文件 @
5c8c9907
...
...
@@ -3,6 +3,8 @@
#include <string>
#include <memory>
#include <Core/Defines.h>
namespace
DB
{
...
...
@@ -17,14 +19,14 @@ class WriteBuffer;
enum
class
CompressionMethod
{
None
,
/// DEFLATE compression with gzip header and CRC32 checksum.
/// This option corresponds to files produced by gzip(1) or HTTP Content-Encoding: gzip.
Gzip
,
/// DEFLATE compression with zlib header and Adler32 checksum.
/// This option corresponds to HTTP Content-Encoding: deflate.
Zlib
,
Brotli
,
None
Brotli
};
/// How the compression method is named in HTTP.
...
...
@@ -37,7 +39,19 @@ std::string toContentEncodingName(CompressionMethod method);
*/
CompressionMethod
chooseCompressionMethod
(
const
std
::
string
&
path
,
const
std
::
string
&
hint
);
std
::
unique_ptr
<
ReadBuffer
>
wrapReadBufferWithCompressionMethod
(
std
::
unique_ptr
<
ReadBuffer
>
nested
,
CompressionMethod
method
);
std
::
unique_ptr
<
WriteBuffer
>
wrapWriteBufferWithCompressionMethod
(
std
::
unique_ptr
<
WriteBuffer
>
nested
,
CompressionMethod
method
,
int
level
);
std
::
unique_ptr
<
ReadBuffer
>
wrapReadBufferWithCompressionMethod
(
std
::
unique_ptr
<
ReadBuffer
>
nested
,
CompressionMethod
method
,
size_t
buf_size
=
DBMS_DEFAULT_BUFFER_SIZE
,
char
*
existing_memory
=
nullptr
,
size_t
alignment
=
0
);
std
::
unique_ptr
<
WriteBuffer
>
wrapWriteBufferWithCompressionMethod
(
std
::
unique_ptr
<
WriteBuffer
>
nested
,
CompressionMethod
method
,
int
level
,
size_t
buf_size
=
DBMS_DEFAULT_BUFFER_SIZE
,
char
*
existing_memory
=
nullptr
,
size_t
alignment
=
0
);
}
dbms/src/IO/WriteBufferFromHTTPServerResponse.cpp
浏览文件 @
5c8c9907
...
...
@@ -111,18 +111,19 @@ void WriteBufferFromHTTPServerResponse::nextImpl()
*
response_header_ostr
<<
"Content-Encoding: "
<<
content_encoding_name
<<
"
\r\n
"
;
#else
response
.
set
(
"Content-Encoding"
,
content_encoding_name
);
response_body_ostr
=
&
(
response
.
send
());
#endif
out
=
wrapWriteBufferWithCompressionMethod
(
std
::
make_unique
<
WriteBufferFromOStream
>
(
*
response_body_ostr
),
compression_method
,
compression_level
);
}
else
{
#if !defined(POCO_CLICKHOUSE_PATCH)
response_body_ostr
=
&
(
response
.
send
());
response_body_ostr
=
&
(
response
.
send
());
#endif
out
=
std
::
make_unique
<
WriteBufferFromOStream
>
(
*
response_body_ostr
);
}
out
=
wrapWriteBufferWithCompressionMethod
(
std
::
make_unique
<
WriteBufferFromOStream
>
(
*
response_body_ostr
),
compress
?
compression_method
:
CompressionMethod
::
None
,
compression_level
,
working_buffer
.
size
(),
working_buffer
.
begin
());
}
finishSendHeaders
();
...
...
@@ -134,9 +135,6 @@ void WriteBufferFromHTTPServerResponse::nextImpl()
out
->
position
()
=
position
();
out
->
next
();
}
internal_buffer
=
out
->
internalBuffer
();
working_buffer
=
out
->
buffer
();
}
...
...
@@ -146,7 +144,7 @@ WriteBufferFromHTTPServerResponse::WriteBufferFromHTTPServerResponse(
unsigned
keep_alive_timeout_
,
bool
compress_
,
CompressionMethod
compression_method_
)
:
WriteBuffer
(
nullptr
,
0
)
:
BufferWithOwnMemory
<
WriteBuffer
>
(
DBMS_DEFAULT_BUFFER_SIZE
)
,
request
(
request_
)
,
response
(
response_
)
,
keep_alive_timeout
(
keep_alive_timeout_
)
...
...
dbms/src/IO/WriteBufferFromHTTPServerResponse.h
浏览文件 @
5c8c9907
...
...
@@ -6,6 +6,7 @@
#include <Poco/Net/HTTPServerResponse.h>
#include <Poco/Version.h>
#include <IO/WriteBuffer.h>
#include <IO/BufferWithOwnMemory.h>
#include <IO/WriteBufferFromOStream.h>
#include <IO/HTTPCommon.h>
#include <IO/Progress.h>
...
...
@@ -39,7 +40,7 @@ namespace DB
/// Also this class write and flush special X-ClickHouse-Progress HTTP headers
/// if no data was sent at the time of progress notification.
/// This allows to implement progress bar in HTTP clients.
class
WriteBufferFromHTTPServerResponse
:
public
WriteBuffer
class
WriteBufferFromHTTPServerResponse
:
public
BufferWithOwnMemory
<
WriteBuffer
>
{
private:
Poco
::
Net
::
HTTPServerRequest
&
request
;
...
...
@@ -90,7 +91,7 @@ public:
Poco
::
Net
::
HTTPServerResponse
&
response_
,
unsigned
keep_alive_timeout_
,
bool
compress_
=
false
,
/// If true - set Content-Encoding header and compress the result.
CompressionMethod
compression_method_
=
CompressionMethod
::
Gzip
);
CompressionMethod
compression_method_
=
CompressionMethod
::
None
);
/// Writes progess in repeating HTTP headers.
void
onProgress
(
const
Progress
&
progress
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录