Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
B
brpc
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
submodule
brpc
Commits
27a3cd51
Commit
27a3cd51
authored
Sep 26, 2018
by
gejun
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Try to convert h2 error in RST_STREAM to related status code
parent
5a487ac1
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
43 additions
and
17 deletions
+43
-17
http2.cpp
src/brpc/http2.cpp
+27
-0
http2.h
src/brpc/http2.h
+5
-1
http2_rpc_protocol.cpp
src/brpc/policy/http2_rpc_protocol.cpp
+1
-1
http_rpc_protocol.cpp
src/brpc/policy/http_rpc_protocol.cpp
+10
-15
No files found.
src/brpc/http2.cpp
View file @
27a3cd51
...
...
@@ -82,4 +82,31 @@ const char* H2ErrorToString(H2Error e) {
return
"Unknown-H2Error"
;
}
int
H2ErrorToStatusCode
(
H2Error
e
)
{
switch
(
e
)
{
case
H2_NO_ERROR
:
return
HTTP_STATUS_OK
;
case
H2_SETTINGS_TIMEOUT
:
return
HTTP_STATUS_GATEWAY_TIMEOUT
;
case
H2_STREAM_CLOSED_ERROR
:
return
HTTP_STATUS_BAD_REQUEST
;
case
H2_REFUSED_STREAM
:
case
H2_CANCEL
:
case
H2_ENHANCE_YOUR_CALM
:
return
HTTP_STATUS_SERVICE_UNAVAILABLE
;
case
H2_INADEQUATE_SECURITY
:
return
HTTP_STATUS_UNAUTHORIZED
;
case
H2_HTTP_1_1_REQUIRED
:
return
HTTP_STATUS_VERSION_NOT_SUPPORTED
;
case
H2_PROTOCOL_ERROR
:
case
H2_FLOW_CONTROL_ERROR
:
case
H2_FRAME_SIZE_ERROR
:
case
H2_COMPRESSION_ERROR
:
case
H2_CONNECT_ERROR
:
case
H2_INTERNAL_ERROR
:
return
HTTP_STATUS_INTERNAL_SERVER_ERROR
;
}
return
HTTP_STATUS_INTERNAL_SERVER_ERROR
;
}
}
// namespace brpc
src/brpc/http2.h
View file @
27a3cd51
...
...
@@ -15,7 +15,7 @@
#ifndef BAIDU_RPC_HTTP2_H
#define BAIDU_RPC_HTTP2_H
#include "b
util/iobuf
.h"
#include "b
rpc/http_status_code
.h"
// To baidu-rpc developers: This is a header included by user, don't depend
// on internal structures, use opaque pointers instead.
...
...
@@ -111,8 +111,12 @@ enum H2Error {
H2_HTTP_1_1_REQUIRED
=
0xd
,
// Use HTTP/1.1 for the request
};
// Get description of the error.
const
char
*
H2ErrorToString
(
H2Error
e
);
// Convert the error to status code with similar semantics
int
H2ErrorToStatusCode
(
H2Error
e
);
}
// namespace brpc
#endif // BAIDU_RPC_HTTP2_H
src/brpc/policy/http2_rpc_protocol.cpp
View file @
27a3cd51
...
...
@@ -785,7 +785,7 @@ H2ParseResult H2StreamContext::OnResetStream(
return
MakeH2Error
(
H2_PROTOCOL_ERROR
);
}
if
(
_conn_ctx
->
is_client_side
())
{
sctx
->
header
().
set_status_code
(
H
TTP_STATUS_INTERNAL_SERVER_ERROR
);
sctx
->
header
().
set_status_code
(
H
2ErrorToStatusCode
(
h2_error
)
);
return
MakeH2Message
(
sctx
);
}
else
{
// No need to process the request.
...
...
src/brpc/policy/http_rpc_protocol.cpp
View file @
27a3cd51
...
...
@@ -299,26 +299,21 @@ void ProcessHttpResponse(InputMessageBase* msg) {
// ErrorCode of RPC is unified to EHTTP.
const
int
sc
=
res_header
->
status_code
();
if
(
sc
<
200
||
sc
>=
300
)
{
std
::
string
err
=
butil
::
string_printf
(
"HTTP/%d.%d %d %s"
,
res_header
->
major_version
(),
res_header
->
minor_version
(),
static_cast
<
int
>
(
res_header
->
status_code
()),
res_header
->
reason_phrase
());
if
(
!
res_body
.
empty
())
{
// Use content as error text if it's present. Notice that
// content may be binary data, so the size limit is a must.
std
::
string
body_str
;
res_body
.
copy
_to
(
&
body_st
r
,
std
::
min
((
int
)
res_body
.
size
(),
err
.
append
(
": "
)
;
res_body
.
append
_to
(
&
er
r
,
std
::
min
((
int
)
res_body
.
size
(),
FLAGS_http_max_error_length
));
cntl
->
SetFailed
(
EHTTP
,
"HTTP/%d.%d %d %s: %.*s"
,
res_header
->
major_version
(),
res_header
->
minor_version
(),
static_cast
<
int
>
(
res_header
->
status_code
()),
res_header
->
reason_phrase
(),
(
int
)
body_str
.
size
(),
body_str
.
c_str
());
}
else
{
cntl
->
SetFailed
(
EHTTP
,
"HTTP/%d.%d %d %s"
,
res_header
->
major_version
(),
res_header
->
minor_version
(),
static_cast
<
int
>
(
res_header
->
status_code
()),
res_header
->
reason_phrase
());
}
cntl
->
SetFailed
(
EHTTP
,
"%s"
,
err
.
c_str
());
if
(
cntl
->
response
()
==
NULL
||
cntl
->
response
()
->
GetDescriptor
()
->
field_count
()
==
0
)
{
// A http call. Http users may need the body(containing a html,
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment