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
88ad7672
Commit
88ad7672
authored
Sep 29, 2018
by
gejun
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Not set content-length in h2 & change default content-type of h2 to proto
parent
4a0927af
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
23 additions
and
33 deletions
+23
-33
client.cpp
example/echo_c++/client.cpp
+0
-3
client.cpp
example/multi_threaded_echo_c++/client.cpp
+0
-3
client.cpp
example/multi_threaded_echo_fns_c++/client.cpp
+0
-3
http2_rpc_protocol.cpp
src/brpc/policy/http2_rpc_protocol.cpp
+0
-13
http_rpc_protocol.cpp
src/brpc/policy/http_rpc_protocol.cpp
+23
-11
No files found.
example/echo_c++/client.cpp
View file @
88ad7672
...
...
@@ -28,7 +28,6 @@ DEFINE_string(load_balancer, "", "The algorithm for load balancing");
DEFINE_int32
(
timeout_ms
,
100
,
"RPC timeout in milliseconds"
);
DEFINE_int32
(
max_retry
,
3
,
"Max retries(not including the first RPC)"
);
DEFINE_int32
(
interval_ms
,
1000
,
"Milliseconds between consecutive requests"
);
DEFINE_string
(
http_content_type
,
"application/json"
,
"Content type of http request"
);
int
main
(
int
argc
,
char
*
argv
[])
{
// Parse gflags. We recommend you to use gflags as well.
...
...
@@ -69,8 +68,6 @@ int main(int argc, char* argv[]) {
// Set attachment which is wired to network directly instead of
// being serialized into protobuf messages.
cntl
.
request_attachment
().
append
(
FLAGS_attachment
);
}
else
{
cntl
.
http_request
().
set_content_type
(
FLAGS_http_content_type
);
}
// Because `done'(last parameter) is NULL, this function waits until
...
...
example/multi_threaded_echo_c++/client.cpp
View file @
88ad7672
...
...
@@ -35,7 +35,6 @@ DEFINE_int32(max_retry, 3, "Max retries(not including the first RPC)");
DEFINE_bool
(
dont_fail
,
false
,
"Print fatal when some call failed"
);
DEFINE_bool
(
enable_ssl
,
false
,
"Use SSL connection"
);
DEFINE_int32
(
dummy_port
,
-
1
,
"Launch dummy server at this port"
);
DEFINE_string
(
http_content_type
,
"application/json"
,
"Content type of http request"
);
std
::
string
g_request
;
std
::
string
g_attachment
;
...
...
@@ -62,8 +61,6 @@ static void* sender(void* arg) {
// Set attachment which is wired to network directly instead of
// being serialized into protobuf messages.
cntl
.
request_attachment
().
append
(
g_attachment
);
}
else
{
cntl
.
http_request
().
set_content_type
(
FLAGS_http_content_type
);
}
// Because `done'(last parameter) is NULL, this function waits until
...
...
example/multi_threaded_echo_fns_c++/client.cpp
View file @
88ad7672
...
...
@@ -37,7 +37,6 @@ DEFINE_int32(backup_timeout_ms, -1, "backup timeout in milliseconds");
DEFINE_int32
(
max_retry
,
3
,
"Max retries(not including the first RPC)"
);
DEFINE_bool
(
dont_fail
,
false
,
"Print fatal when some call failed"
);
DEFINE_int32
(
dummy_port
,
-
1
,
"Launch dummy server at this port"
);
DEFINE_string
(
http_content_type
,
"application/json"
,
"Content type of http request"
);
std
::
string
g_attachment
;
...
...
@@ -66,8 +65,6 @@ static void* sender(void* arg) {
// Set attachment which is wired to network directly instead of
// being serialized into protobuf messages.
cntl
.
request_attachment
().
append
(
g_attachment
);
}
else
{
cntl
.
http_request
().
set_content_type
(
FLAGS_http_content_type
);
}
// Because `done'(last parameter) is NULL, this function waits until
...
...
src/brpc/policy/http2_rpc_protocol.cpp
View file @
88ad7672
...
...
@@ -1359,7 +1359,6 @@ static void PackH2Message(butil::IOBuf* out,
H2UnsentRequest
*
H2UnsentRequest
::
New
(
Controller
*
c
)
{
const
HttpHeader
&
h
=
c
->
http_request
();
const
CommonStrings
*
const
common
=
get_common_strings
();
const
bool
need_content_length
=
(
h
.
method
()
!=
HTTP_METHOD_GET
);
const
bool
need_content_type
=
!
h
.
content_type
().
empty
();
const
bool
need_accept
=
!
h
.
GetHeader
(
common
->
ACCEPT
);
const
bool
need_user_agent
=
!
h
.
GetHeader
(
common
->
USER_AGENT
);
...
...
@@ -1367,7 +1366,6 @@ H2UnsentRequest* H2UnsentRequest::New(Controller* c) {
const
bool
need_authorization
=
(
!
user_info
.
empty
()
&&
!
h
.
GetHeader
(
"Authorization"
));
const
size_t
maxsize
=
h
.
HeaderCount
()
+
4
+
(
size_t
)
need_content_length
+
(
size_t
)
need_content_type
+
(
size_t
)
need_accept
+
(
size_t
)
need_user_agent
...
...
@@ -1409,10 +1407,6 @@ H2UnsentRequest* H2UnsentRequest::New(Controller* c) {
*
val
=
butil
::
endpoint2str
(
c
->
remote_side
()).
c_str
();
}
}
if
(
need_content_length
)
{
butil
::
string_printf
(
&
msg
->
push
(
common
->
CONTENT_LENGTH
),
"%"
PRIu64
,
c
->
request_attachment
().
size
());
}
if
(
need_content_type
)
{
msg
->
push
(
common
->
CONTENT_TYPE
,
h
.
content_type
());
}
...
...
@@ -1631,11 +1625,8 @@ H2UnsentResponse::H2UnsentResponse(Controller* c, int stream_id, bool is_grpc)
H2UnsentResponse
*
H2UnsentResponse
::
New
(
Controller
*
c
,
int
stream_id
,
bool
is_grpc
)
{
const
HttpHeader
*
const
h
=
&
c
->
http_response
();
const
CommonStrings
*
const
common
=
get_common_strings
();
const
bool
need_content_length
=
(
c
->
Failed
()
||
!
c
->
has_progressive_writer
());
const
bool
need_content_type
=
!
h
->
content_type
().
empty
();
const
size_t
maxsize
=
1
+
(
size_t
)
need_content_length
+
(
size_t
)
need_content_type
;
const
size_t
memsize
=
offsetof
(
H2UnsentResponse
,
_list
)
+
sizeof
(
HPacker
::
Header
)
*
maxsize
;
...
...
@@ -1647,10 +1638,6 @@ H2UnsentResponse* H2UnsentResponse::New(Controller* c, int stream_id, bool is_gr
butil
::
string_printf
(
&
msg
->
push
(
common
->
H2_STATUS
),
"%d"
,
h
->
status_code
());
}
if
(
need_content_length
)
{
butil
::
string_printf
(
&
msg
->
push
(
common
->
CONTENT_LENGTH
),
"%"
PRIu64
,
msg
->
_data
.
size
());
}
if
(
need_content_type
)
{
msg
->
push
(
common
->
CONTENT_TYPE
,
h
->
content_type
());
}
...
...
src/brpc/policy/http_rpc_protocol.cpp
View file @
88ad7672
...
...
@@ -111,7 +111,6 @@ CommonStrings::CommonStrings()
,
AUTHORIZATION
(
"authorization"
)
,
ACCEPT_ENCODING
(
"accept-encoding"
)
,
CONTENT_ENCODING
(
"content-encoding"
)
,
CONTENT_LENGTH
(
"content-length"
)
,
GZIP
(
"gzip"
)
,
CONNECTION
(
"connection"
)
,
KEEP_ALIVE
(
"keep-alive"
)
...
...
@@ -455,7 +454,7 @@ void SerializeHttpRequest(butil::IOBuf* /*not used*/,
const
bool
is_http2
=
(
cntl
->
request_protocol
()
==
PROTOCOL_HTTP2
);
bool
is_grpc
=
false
;
if
(
request
!=
NULL
)
{
// If request is not NULL, message body will be serialized json,
// If request is not NULL, message body will be serialized
proto/
json,
if
(
!
request
->
IsInitialized
())
{
return
cntl
->
SetFailed
(
EREQUEST
,
"Missing required fields in request: %s"
,
...
...
@@ -465,11 +464,25 @@ void SerializeHttpRequest(butil::IOBuf* /*not used*/,
return
cntl
->
SetFailed
(
EREQUEST
,
"request_attachment must be empty "
"when request is not NULL"
);
}
HttpContentType
content_type
=
HTTP_CONTENT_OTHERS
;
if
(
cntl
->
http_request
().
content_type
().
empty
())
{
// Set content-type if user did not.
// Note that http1.x defaults to json and h2 defaults to pb.
if
(
is_http2
)
{
content_type
=
HTTP_CONTENT_PROTO
;
cntl
->
http_request
().
set_content_type
(
common
->
CONTENT_TYPE_PROTO
);
}
else
{
content_type
=
HTTP_CONTENT_JSON
;
cntl
->
http_request
().
set_content_type
(
common
->
CONTENT_TYPE_JSON
);
}
}
else
{
bool
is_grpc_ct
=
false
;
content_type
=
ParseContentType
(
cntl
->
http_request
().
content_type
(),
&
is_grpc_ct
);
is_grpc
=
(
is_http2
&&
is_grpc_ct
);
}
butil
::
IOBufAsZeroCopyOutputStream
wrapper
(
&
cntl
->
request_attachment
());
bool
is_grpc_ct
=
false
;
const
HttpContentType
content_type
=
ParseContentType
(
cntl
->
http_request
().
content_type
(),
&
is_grpc_ct
);
is_grpc
=
(
is_http2
&&
is_grpc_ct
);
if
(
content_type
==
HTTP_CONTENT_PROTO
)
{
// Serialize content as protobuf
if
(
!
request
->
SerializeToZeroCopyStream
(
&
wrapper
))
{
...
...
@@ -477,7 +490,7 @@ void SerializeHttpRequest(butil::IOBuf* /*not used*/,
return
cntl
->
SetFailed
(
EREQUEST
,
"Fail to serialize %s"
,
request
->
GetTypeName
().
c_str
());
}
}
else
{
// Serialize content as json
}
else
if
(
content_type
==
HTTP_CONTENT_JSON
)
{
std
::
string
err
;
json2pb
::
Pb2JsonOptions
opt
;
opt
.
bytes_to_base64
=
cntl
->
has_pb_bytes_to_base64
();
...
...
@@ -489,10 +502,9 @@ void SerializeHttpRequest(butil::IOBuf* /*not used*/,
cntl
->
request_attachment
().
clear
();
return
cntl
->
SetFailed
(
EREQUEST
,
"Fail to convert request to json, %s"
,
err
.
c_str
());
}
// Set content-type if user did not.
if
(
cntl
->
http_request
().
content_type
().
empty
())
{
cntl
->
http_request
().
set_content_type
(
common
->
CONTENT_TYPE_JSON
);
}
}
else
{
return
cntl
->
SetFailed
(
EREQUEST
,
"Unknown content_type=%s"
,
cntl
->
http_request
().
content_type
().
c_str
());
}
}
else
{
// Use request_attachment.
...
...
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