Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
2dot5
ClickHouse
提交
78aa5d59
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,发现更多精彩内容 >>
提交
78aa5d59
编写于
2月 06, 2017
作者:
A
artpaul
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
implement conversion from error codes to different http statuses
上级
84e4fb00
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
92 addition
and
21 deletion
+92
-21
dbms/src/Server/HTTPHandler.cpp
dbms/src/Server/HTTPHandler.cpp
+84
-9
dbms/src/Server/HTTPHandler.h
dbms/src/Server/HTTPHandler.h
+8
-12
未找到文件。
dbms/src/Server/HTTPHandler.cpp
浏览文件 @
78aa5d59
...
...
@@ -2,6 +2,7 @@
#include <Poco/Net/HTTPBasicCredentials.h>
#include <DB/Common/ExternalTable.h>
#include <DB/Common/StringUtils.h>
#include <DB/IO/ReadBufferFromIStream.h>
...
...
@@ -19,12 +20,8 @@
#include <DB/Interpreters/executeQuery.h>
#include <DB/Interpreters/Quota.h>
#include <DB/Common/ExternalTable.h>
#include "HTTPHandler.h"
namespace
DB
{
...
...
@@ -33,11 +30,90 @@ namespace ErrorCodes
extern
const
int
READONLY
;
extern
const
int
UNKNOWN_COMPRESSION_METHOD
;
extern
const
int
CANNOT_PARSE_TEXT
;
extern
const
int
CANNOT_PARSE_ESCAPE_SEQUENCE
;
extern
const
int
CANNOT_PARSE_QUOTED_STRING
;
extern
const
int
CANNOT_PARSE_DATE
;
extern
const
int
CANNOT_PARSE_DATETIME
;
extern
const
int
CANNOT_PARSE_NUMBER
;
extern
const
int
UNKNOWN_ELEMENT_IN_AST
;
extern
const
int
UNKNOWN_TYPE_OF_AST_NODE
;
extern
const
int
TOO_DEEP_AST
;
extern
const
int
TOO_BIG_AST
;
extern
const
int
UNEXPECTED_AST_STRUCTURE
;
extern
const
int
UNKNOWN_TABLE
;
extern
const
int
UNKNOWN_FUNCTION
;
extern
const
int
UNKNOWN_IDENTIFIER
;
extern
const
int
UNKNOWN_TYPE
;
extern
const
int
UNKNOWN_STORAGE
;
extern
const
int
UNKNOWN_DATABASE
;
extern
const
int
UNKNOWN_SETTING
;
extern
const
int
UNKNOWN_DIRECTION_OF_SORTING
;
extern
const
int
UNKNOWN_AGGREGATE_FUNCTION
;
extern
const
int
UNKNOWN_FORMAT
;
extern
const
int
UNKNOWN_DATABASE_ENGINE
;
extern
const
int
UNKNOWN_TYPE_OF_QUERY
;
extern
const
int
QUERY_IS_TOO_LARGE
;
extern
const
int
NOT_IMPLEMENTED
;
extern
const
int
SOCKET_TIMEOUT
;
extern
const
int
UNKNOWN_USER
;
extern
const
int
WRONG_PASSWORD
;
extern
const
int
REQUIRED_PASSWORD
;
}
static
Poco
::
Net
::
HTTPResponse
::
HTTPStatus
exceptionCodeToHttpStatus
(
int
exception_code
)
{
using
namespace
Poco
::
Net
;
if
(
exception_code
==
ErrorCodes
::
REQUIRED_PASSWORD
)
return
HTTPResponse
::
HTTP_UNAUTHORIZED
;
else
if
(
exception_code
==
ErrorCodes
::
CANNOT_PARSE_TEXT
||
exception_code
==
ErrorCodes
::
CANNOT_PARSE_ESCAPE_SEQUENCE
||
exception_code
==
ErrorCodes
::
CANNOT_PARSE_QUOTED_STRING
||
exception_code
==
ErrorCodes
::
CANNOT_PARSE_DATE
||
exception_code
==
ErrorCodes
::
CANNOT_PARSE_DATETIME
||
exception_code
==
ErrorCodes
::
CANNOT_PARSE_NUMBER
)
return
HTTPResponse
::
HTTP_BAD_REQUEST
;
else
if
(
exception_code
==
ErrorCodes
::
UNKNOWN_ELEMENT_IN_AST
||
exception_code
==
ErrorCodes
::
UNKNOWN_TYPE_OF_AST_NODE
||
exception_code
==
ErrorCodes
::
TOO_DEEP_AST
||
exception_code
==
ErrorCodes
::
TOO_BIG_AST
||
exception_code
==
ErrorCodes
::
UNEXPECTED_AST_STRUCTURE
)
return
HTTPResponse
::
HTTP_BAD_REQUEST
;
else
if
(
exception_code
==
ErrorCodes
::
UNKNOWN_TABLE
||
exception_code
==
ErrorCodes
::
UNKNOWN_FUNCTION
||
exception_code
==
ErrorCodes
::
UNKNOWN_IDENTIFIER
||
exception_code
==
ErrorCodes
::
UNKNOWN_TYPE
||
exception_code
==
ErrorCodes
::
UNKNOWN_STORAGE
||
exception_code
==
ErrorCodes
::
UNKNOWN_DATABASE
||
exception_code
==
ErrorCodes
::
UNKNOWN_SETTING
||
exception_code
==
ErrorCodes
::
UNKNOWN_DIRECTION_OF_SORTING
||
exception_code
==
ErrorCodes
::
UNKNOWN_AGGREGATE_FUNCTION
||
exception_code
==
ErrorCodes
::
UNKNOWN_FORMAT
||
exception_code
==
ErrorCodes
::
UNKNOWN_DATABASE_ENGINE
)
return
HTTPResponse
::
HTTP_NOT_FOUND
;
else
if
(
exception_code
==
ErrorCodes
::
UNKNOWN_TYPE_OF_QUERY
)
return
HTTPResponse
::
HTTP_NOT_FOUND
;
else
if
(
exception_code
==
ErrorCodes
::
QUERY_IS_TOO_LARGE
)
return
HTTPResponse
::
HTTP_REQUESTENTITYTOOLARGE
;
else
if
(
exception_code
==
ErrorCodes
::
NOT_IMPLEMENTED
)
return
HTTPResponse
::
HTTP_NOT_IMPLEMENTED
;
else
if
(
exception_code
==
ErrorCodes
::
SOCKET_TIMEOUT
)
return
HTTPResponse
::
HTTP_SERVICE_UNAVAILABLE
;
return
HTTPResponse
::
HTTP_INTERNAL_SERVER_ERROR
;
}
HTTPHandler
::
HTTPHandler
(
Server
&
server_
)
:
server
(
server_
)
,
log
(
&
Logger
::
get
(
"HTTPHandler"
))
{
}
void
HTTPHandler
::
processQuery
(
Poco
::
Net
::
HTTPServerRequest
&
request
,
...
...
@@ -275,7 +351,6 @@ void HTTPHandler::processQuery(
used_output
.
out
->
finalize
();
}
void
HTTPHandler
::
trySendExceptionToClient
(
const
std
::
string
&
s
,
int
exception_code
,
Poco
::
Net
::
HTTPServerRequest
&
request
,
Poco
::
Net
::
HTTPServerResponse
&
response
,
Output
&
used_output
)
...
...
@@ -291,8 +366,9 @@ void HTTPHandler::trySendExceptionToClient(const std::string & s, int exception_
request
.
stream
().
ignore
(
std
::
numeric_limits
<
std
::
streamsize
>::
max
());
}
bool
auth_fail
=
exception_code
==
ErrorCodes
::
UNKNOWN_USER
||
exception_code
==
ErrorCodes
::
WRONG_PASSWORD
||
exception_code
==
ErrorCodes
::
REQUIRED_PASSWORD
;
bool
auth_fail
=
exception_code
==
ErrorCodes
::
UNKNOWN_USER
||
exception_code
==
ErrorCodes
::
WRONG_PASSWORD
||
exception_code
==
ErrorCodes
::
REQUIRED_PASSWORD
;
if
(
auth_fail
)
{
...
...
@@ -300,7 +376,7 @@ void HTTPHandler::trySendExceptionToClient(const std::string & s, int exception_
}
else
{
response
.
setStatusAndReason
(
Poco
::
Net
::
HTTPResponse
::
HTTP_INTERNAL_SERVER_ERROR
);
response
.
setStatusAndReason
(
exceptionCodeToHttpStatus
(
exception_code
)
);
}
if
(
!
response
.
sent
()
&&
!
used_output
.
out_maybe_compressed
)
...
...
@@ -351,7 +427,6 @@ static int getCurrentExceptionCode()
return
0
;
}
void
HTTPHandler
::
handleRequest
(
Poco
::
Net
::
HTTPServerRequest
&
request
,
Poco
::
Net
::
HTTPServerResponse
&
response
)
{
Output
used_output
;
...
...
dbms/src/Server/HTTPHandler.h
浏览文件 @
78aa5d59
...
...
@@ -17,12 +17,11 @@ class WriteBufferFromHTTPServerResponse;
class
HTTPHandler
:
public
Poco
::
Net
::
HTTPRequestHandler
{
public:
HTTPHandler
(
Server
&
server_
)
:
server
(
server_
)
,
log
(
&
Logger
::
get
(
"HTTPHandler"
))
{
}
explicit
HTTPHandler
(
Server
&
server_
);
void
handleRequest
(
Poco
::
Net
::
HTTPServerRequest
&
request
,
Poco
::
Net
::
HTTPServerResponse
&
response
)
override
;
private:
struct
Output
{
std
::
shared_ptr
<
WriteBufferFromHTTPServerResponse
>
out
;
...
...
@@ -30,13 +29,6 @@ public:
std
::
shared_ptr
<
WriteBuffer
>
out_maybe_compressed
;
};
void
handleRequest
(
Poco
::
Net
::
HTTPServerRequest
&
request
,
Poco
::
Net
::
HTTPServerResponse
&
response
)
override
;
void
trySendExceptionToClient
(
const
std
::
string
&
s
,
int
exception_code
,
Poco
::
Net
::
HTTPServerRequest
&
request
,
Poco
::
Net
::
HTTPServerResponse
&
response
,
Output
&
used_output
);
private:
Server
&
server
;
CurrentMetrics
::
Increment
metric_increment
{
CurrentMetrics
::
HTTPConnection
};
...
...
@@ -49,6 +41,10 @@ private:
HTMLForm
&
params
,
Poco
::
Net
::
HTTPServerResponse
&
response
,
Output
&
used_output
);
void
trySendExceptionToClient
(
const
std
::
string
&
s
,
int
exception_code
,
Poco
::
Net
::
HTTPServerRequest
&
request
,
Poco
::
Net
::
HTTPServerResponse
&
response
,
Output
&
used_output
);
};
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录