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
2e471c02
Commit
2e471c02
authored
6 years ago
by
zhujiashun
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix PercentEncode
parent
6dd0af66
master
0.9.8-rc01
0.9.7
0.9.7-rc03
0.9.7-rc02
0.9.7-rc01
0.9.6
0.9.6-rc03
0.9.6-rc02
0.9.6-rc01
0.9.5
No related merge requests found
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
29 additions
and
20 deletions
+29
-20
grpc.cpp
src/brpc/grpc.cpp
+7
-3
grpc.h
src/brpc/grpc.h
+2
-2
http2_rpc_protocol.cpp
src/brpc/policy/http2_rpc_protocol.cpp
+1
-3
http_rpc_protocol.cpp
src/brpc/policy/http_rpc_protocol.cpp
+8
-3
brpc_grpc_protocol_unittest.cpp
test/brpc_grpc_protocol_unittest.cpp
+11
-9
No files found.
src/brpc/grpc.cpp
View file @
2e471c02
...
...
@@ -52,14 +52,18 @@ int GrpcStatusToErrorCode(GrpcStatus grpc_status) {
return
EINTERNAL
;
}
void
percent_e
ncode
(
const
std
::
string
&
str
,
std
::
string
*
str_out
)
{
void
PercentE
ncode
(
const
std
::
string
&
str
,
std
::
string
*
str_out
)
{
std
::
ostringstream
escaped
;
escaped
.
fill
(
'0'
);
escaped
<<
std
::
hex
;
for
(
std
::
string
::
const_iterator
it
=
str
.
begin
();
it
!=
str
.
end
();
++
it
)
{
const
std
::
string
::
value_type
&
c
=
*
it
;
if
(
c
>=
' '
&&
c
<=
'~'
&&
c
!=
'%'
)
{
// Unreserved Characters are referred from
// https://en.wikipedia.org/wiki/Percent-encoding
if
((
c
>=
'a'
&&
c
<=
'z'
)
||
(
c
>=
'A'
&&
c
<=
'Z'
)
||
c
==
'-'
||
c
==
'_'
||
c
==
'.'
||
c
==
'~'
)
{
escaped
<<
c
;
continue
;
}
...
...
@@ -81,7 +85,7 @@ static int hex_to_int(char c) {
return
0
;
}
void
percent_d
ecode
(
const
std
::
string
&
str
,
std
::
string
*
str_out
)
{
void
PercentD
ecode
(
const
std
::
string
&
str
,
std
::
string
*
str_out
)
{
std
::
ostringstream
unescaped
;
for
(
std
::
string
::
const_iterator
it
=
str
.
begin
();
it
!=
str
.
end
();
++
it
)
{
...
...
This diff is collapsed.
Click to expand it.
src/brpc/grpc.h
View file @
2e471c02
...
...
@@ -146,9 +146,9 @@ GrpcStatus ErrorCodeToGrpcStatus(int error_code);
int
GrpcStatusToErrorCode
(
GrpcStatus
grpc_status
);
void
percent_e
ncode
(
const
std
::
string
&
str
,
std
::
string
*
str_out
);
void
PercentE
ncode
(
const
std
::
string
&
str
,
std
::
string
*
str_out
);
void
percent_d
ecode
(
const
std
::
string
&
str
,
std
::
string
*
str_out
);
void
PercentD
ecode
(
const
std
::
string
&
str
,
std
::
string
*
str_out
);
}
// namespace brpc
...
...
This diff is collapsed.
Click to expand it.
src/brpc/policy/http2_rpc_protocol.cpp
View file @
2e471c02
...
...
@@ -1206,8 +1206,6 @@ int H2StreamContext::ConsumeHeaders(butil::IOBufBytesIterator& it) {
if
(
rc
==
0
)
{
break
;
}
RPC_VLOG
<<
"Header name: "
<<
pair
.
name
<<
", header value: "
<<
pair
.
value
;
const
char
*
const
name
=
pair
.
name
.
c_str
();
bool
matched
=
false
;
if
(
name
[
0
]
==
':'
)
{
// reserved names
...
...
@@ -1637,7 +1635,7 @@ H2UnsentResponse::H2UnsentResponse(Controller* c, int stream_id, bool grpc)
_data
.
swap
(
c
->
response_attachment
());
if
(
grpc
)
{
_grpc_status
=
ErrorCodeToGrpcStatus
(
c
->
ErrorCode
());
percent_e
ncode
(
c
->
ErrorText
(),
&
_grpc_message
);
PercentE
ncode
(
c
->
ErrorText
(),
&
_grpc_message
);
}
}
...
...
This diff is collapsed.
Click to expand it.
src/brpc/policy/http_rpc_protocol.cpp
View file @
2e471c02
...
...
@@ -364,9 +364,14 @@ void ProcessHttpResponse(InputMessageBase* msg) {
if
(
grpc_status
)
{
GrpcStatus
status
=
(
GrpcStatus
)
strtol
(
grpc_status
->
data
(),
NULL
,
10
);
if
(
status
!=
GRPC_OK
)
{
const
std
::
string
err
=
grpc_message
?
grpc_message
->
data
()
:
"Unknown grpc error"
;
cntl
->
SetFailed
(
GrpcStatusToErrorCode
(
status
),
"%s"
,
err
.
c_str
());
std
::
string
message_decoded
;
if
(
grpc_message
)
{
PercentDecode
(
*
grpc_message
,
&
message_decoded
);
}
else
{
message_decoded
=
"Unknown grpc error"
;
}
cntl
->
SetFailed
(
GrpcStatusToErrorCode
(
status
),
"%s"
,
message_decoded
.
c_str
());
break
;
}
}
...
...
This diff is collapsed.
Click to expand it.
test/brpc_grpc_protocol_unittest.cpp
View file @
2e471c02
...
...
@@ -120,26 +120,28 @@ protected:
TEST_F
(
GrpcTest
,
percent_encode
)
{
std
::
string
out
;
std
::
string
s1
(
"abcdefg !@#$^&*()/"
);
brpc
::
percent_encode
(
s1
,
&
out
);
EXPECT_TRUE
(
out
==
s1
)
<<
s1
<<
" vs "
<<
out
;
std
::
string
s1_out
(
"abcdefg%20%21%40%23%24%5e%26%2a%28%29%2f"
);
brpc
::
PercentEncode
(
s1
,
&
out
);
EXPECT_TRUE
(
out
==
s1_out
)
<<
s1_out
<<
" vs "
<<
out
;
char
s2_buf
[]
=
"
\0\0
%
\33\35
brpc"
;
std
::
string
s2
(
s2_buf
,
sizeof
(
s2_buf
)
-
1
);
std
::
string
s2_expected_out
(
"%00%00%25%1b%1d
brpc"
);
brpc
::
percent_e
ncode
(
s2
,
&
out
);
std
::
string
s2_expected_out
(
"%00%00%25%1b%1d
%20
brpc"
);
brpc
::
PercentE
ncode
(
s2
,
&
out
);
EXPECT_TRUE
(
out
==
s2_expected_out
)
<<
s2_expected_out
<<
" vs "
<<
out
;
}
TEST_F
(
GrpcTest
,
percent_decode
)
{
std
::
string
out
;
std
::
string
s1
(
"abcdefg !@#$^&*()/"
);
brpc
::
percent_decode
(
s1
,
&
out
);
EXPECT_TRUE
(
out
==
s1
)
<<
s1
<<
" vs "
<<
out
;
std
::
string
s1
(
"abcdefg%20%21%40%23%24%5e%26%2a%28%29%2f"
);
std
::
string
s1_out
(
"abcdefg !@#$^&*()/"
);
brpc
::
PercentDecode
(
s1
,
&
out
);
EXPECT_TRUE
(
out
==
s1_out
)
<<
s1_out
<<
" vs "
<<
out
;
std
::
string
s2
(
"%00%00%1b%1d
brpc"
);
std
::
string
s2
(
"%00%00%1b%1d
%20
brpc"
);
char
s2_expected_out_buf
[]
=
"
\0\0\33\35
brpc"
;
std
::
string
s2_expected_out
(
s2_expected_out_buf
,
sizeof
(
s2_expected_out_buf
)
-
1
);
brpc
::
percent_d
ecode
(
s2
,
&
out
);
brpc
::
PercentD
ecode
(
s2
,
&
out
);
EXPECT_TRUE
(
out
==
s2_expected_out
)
<<
s2_expected_out
<<
" vs "
<<
out
;
}
...
...
This diff is collapsed.
Click to expand it.
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