Commit d50f3fa9 authored by wxf's avatar wxf

rename restful_mapped_only to allow_default_url

parent 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 && mp->restful_mapped_only) {
if (mp->http_url != NULL && !mp->params.allow_default_url) {
// the restful method is accessed from its
// default url (SERVICE/METHOD) which should be rejected.
return NULL;
......
......@@ -155,6 +155,7 @@ ServerSSLOptions* ServerOptions::mutable_ssl_options() {
Server::MethodProperty::OpaqueParams::OpaqueParams()
: is_tabbed(false)
, allow_default_url(false)
, allow_http_body_to_pb(true)
, pb_bytes_to_base64(false) {
}
......@@ -1207,6 +1208,7 @@ int Server::AddServiceInternal(google::protobuf::Service* service,
mp.is_builtin_service = is_builtin_service;
mp.own_method_status = true;
mp.params.is_tabbed = !!tabbed;
mp.params.allow_default_url = svc_opt.allow_default_url;
mp.params.allow_http_body_to_pb = svc_opt.allow_http_body_to_pb;
mp.params.pb_bytes_to_base64 = svc_opt.pb_bytes_to_base64;
mp.service = service;
......@@ -1293,6 +1295,7 @@ int Server::AddServiceInternal(google::protobuf::Service* service,
}
MethodProperty::OpaqueParams params;
params.is_tabbed = !!tabbed;
params.allow_default_url = svc_opt.allow_default_url;
params.allow_http_body_to_pb = svc_opt.allow_http_body_to_pb;
params.pb_bytes_to_base64 = svc_opt.pb_bytes_to_base64;
if (!_global_restful_map->AddMethod(
......@@ -1305,7 +1308,6 @@ 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(" @");
......@@ -1331,6 +1333,7 @@ int Server::AddServiceInternal(google::protobuf::Service* service,
}
MethodProperty::OpaqueParams params;
params.is_tabbed = !!tabbed;
params.allow_default_url = svc_opt.allow_default_url;
params.allow_http_body_to_pb = svc_opt.allow_http_body_to_pb;
params.pb_bytes_to_base64 = svc_opt.pb_bytes_to_base64;
if (!m->AddMethod(mappings[i].path, service, params,
......@@ -1346,7 +1349,6 @@ 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(" @");
......@@ -1386,7 +1388,7 @@ int Server::AddServiceInternal(google::protobuf::Service* service,
ServiceOptions::ServiceOptions()
: ownership(SERVER_DOESNT_OWN_SERVICE)
, restful_mapped_only(true)
, allow_default_url(false)
, allow_http_body_to_pb(true)
#ifdef BAIDU_INTERNAL
, pb_bytes_to_base64(false)
......@@ -1405,12 +1407,12 @@ int Server::AddService(google::protobuf::Service* service,
int Server::AddService(google::protobuf::Service* service,
ServiceOwnership ownership,
const butil::StringPiece& restful_mappings,
bool restful_mapped_only) {
bool allow_default_url) {
ServiceOptions options;
options.ownership = ownership;
// TODO: This is weird
options.restful_mappings = restful_mappings.as_string();
options.restful_mapped_only = restful_mapped_only;
options.allow_default_url = allow_default_url;
return AddServiceInternal(service, false, options);
}
......
......@@ -277,10 +277,10 @@ struct ServiceOptions {
// Default: empty
std::string restful_mappings;
// Work with restful_mappings, if this flag is true, reject methods accessed
// Work with restful_mappings, if this flag is false, reject methods accessed
// from default urls (SERVICE/METHOD).
// Default: true
bool restful_mapped_only;
// Default: false
bool allow_default_url;
// [ Not recommended to change this option ]
// If this flag is true, the service will convert http body to protobuf
......@@ -339,11 +339,11 @@ 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 {
bool is_tabbed;
bool allow_default_url;
bool allow_http_body_to_pb;
bool pb_bytes_to_base64;
OpaqueParams();
......@@ -421,7 +421,7 @@ public:
int AddService(google::protobuf::Service* service,
ServiceOwnership ownership,
const butil::StringPiece& restful_mappings,
bool restful_mapped_only = true);
bool allow_default_url = false);
int AddService(google::protobuf::Service* service,
const ServiceOptions& options);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment