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
ca66d1fe
Commit
ca66d1fe
authored
Aug 22, 2020
by
wxf
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add option to allow access methods from default url
parent
7de0d7ea
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
15 additions
and
3 deletions
+15
-3
http_rpc_protocol.cpp
src/brpc/policy/http_rpc_protocol.cpp
+1
-1
server.cpp
src/brpc/server.cpp
+6
-1
server.h
src/brpc/server.h
+8
-1
No files found.
src/brpc/policy/http_rpc_protocol.cpp
View file @
ca66d1fe
...
...
@@ -1011,7 +1011,7 @@ FindMethodPropertyByURI(const std::string& uri_path, const Server* server,
const
Server
::
MethodProperty
*
mp
=
FindMethodPropertyByURIImpl
(
uri_path
,
server
,
unresolved_path
);
if
(
mp
!=
NULL
)
{
if
(
mp
->
http_url
!=
NULL
)
{
if
(
mp
->
http_url
!=
NULL
&&
mp
->
restful_mapped_only
)
{
// the restful method is accessed from its
// default url (SERVICE/METHOD) which should be rejected.
return
NULL
;
...
...
src/brpc/server.cpp
View file @
ca66d1fe
...
...
@@ -1305,6 +1305,7 @@ int Server::AddServiceInternal(google::protobuf::Service* service,
}
if
(
mp
->
http_url
==
NULL
)
{
mp
->
http_url
=
new
std
::
string
(
mappings
[
i
].
path
.
to_string
());
mp
->
restful_mapped_only
=
svc_opt
.
restful_mapped_only
;
}
else
{
if
(
!
mp
->
http_url
->
empty
())
{
mp
->
http_url
->
append
(
" @"
);
...
...
@@ -1345,6 +1346,7 @@ int Server::AddServiceInternal(google::protobuf::Service* service,
}
if
(
mp
->
http_url
==
NULL
)
{
mp
->
http_url
=
new
std
::
string
(
mappings
[
i
].
path
.
to_string
());
mp
->
restful_mapped_only
=
svc_opt
.
restful_mapped_only
;
}
else
{
if
(
!
mp
->
http_url
->
empty
())
{
mp
->
http_url
->
append
(
" @"
);
...
...
@@ -1384,6 +1386,7 @@ int Server::AddServiceInternal(google::protobuf::Service* service,
ServiceOptions
::
ServiceOptions
()
:
ownership
(
SERVER_DOESNT_OWN_SERVICE
)
,
restful_mapped_only
(
true
)
,
allow_http_body_to_pb
(
true
)
#ifdef BAIDU_INTERNAL
,
pb_bytes_to_base64
(
false
)
...
...
@@ -1401,11 +1404,13 @@ int Server::AddService(google::protobuf::Service* service,
int
Server
::
AddService
(
google
::
protobuf
::
Service
*
service
,
ServiceOwnership
ownership
,
const
butil
::
StringPiece
&
restful_mappings
)
{
const
butil
::
StringPiece
&
restful_mappings
,
bool
restful_mapped_only
)
{
ServiceOptions
options
;
options
.
ownership
=
ownership
;
// TODO: This is weird
options
.
restful_mappings
=
restful_mappings
.
as_string
();
options
.
restful_mapped_only
=
restful_mapped_only
;
return
AddServiceInternal
(
service
,
false
,
options
);
}
...
...
src/brpc/server.h
View file @
ca66d1fe
...
...
@@ -277,6 +277,11 @@ struct ServiceOptions {
// Default: empty
std
::
string
restful_mappings
;
// Work with restful_mappings, if this flag is true, reject methods accessed
// from default urls (SERVICE/METHOD).
// Default: true
bool
restful_mapped_only
;
// [ Not recommended to change this option ]
// If this flag is true, the service will convert http body to protobuf
// when the pb schema is non-empty in http servings. The body must be
...
...
@@ -334,6 +339,7 @@ public:
struct
MethodProperty
{
bool
is_builtin_service
;
bool
own_method_status
;
bool
restful_mapped_only
;
// Parameters which have nothing to do with management of services, but
// will be used when the service is queried.
struct
OpaqueParams
{
...
...
@@ -414,7 +420,8 @@ public:
ServiceOwnership
ownership
);
int
AddService
(
google
::
protobuf
::
Service
*
service
,
ServiceOwnership
ownership
,
const
butil
::
StringPiece
&
restful_mappings
);
const
butil
::
StringPiece
&
restful_mappings
,
bool
restful_mapped_only
=
true
);
int
AddService
(
google
::
protobuf
::
Service
*
service
,
const
ServiceOptions
&
options
);
...
...
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