rgw::io::add_conlen_controlling(
&real_client))));
RGWRestfulIO client(&real_client_io);
- process_request(env.store, env.rest, &req, &client, env.olog);
+ process_request(env.store, env.rest, &req, env.uri_prefix, &client,
+ env.olog);
}
void write_bad_request() {
RGWCivetWeb(conn, env.port)))));
RGWRestfulIO client_io(&real_client_io);
- int ret = process_request(env.store, env.rest, &req, &client_io, env.olog);
+ int ret = process_request(env.store, env.rest, &req, env.uri_prefix,
+ &client_io, env.olog);
if (ret < 0) {
/* We don't really care about return code. */
dout(20) << "process_request() returned " << ret << dendl;
RGWRestfulIO client_io(&real_client_io);
- int ret = process_request(store, rest, req, &client_io, olog);
+ int ret = process_request(store, rest, req, uri_prefix, &client_io, olog);
if (ret < 0) {
/* we don't really care about return code */
dout(20) << "process_request() returned " << ret << dendl;
RGWLoadGenIO real_client_io(&env);
RGWRestfulIO client_io(&real_client_io);
- int ret = process_request(store, rest, req, &client_io, olog);
+ int ret = process_request(store, rest, req, uri_prefix, &client_io, olog);
if (ret < 0) {
/* we don't really care about return code */
dout(20) << "process_request() returned " << ret << dendl;
return 0;
}
-int process_request(RGWRados* store, RGWREST* rest, RGWRequest* req,
- RGWRestfulIO* client_io, OpsLogSocket* olog)
+int process_request(RGWRados* const store,
+ RGWREST* const rest,
+ RGWRequest* const req,
+ const std::string& frontend_prefix,
+ RGWRestfulIO* const client_io,
+ OpsLogSocket* const olog)
{
int ret = 0;
int init_error = 0;
bool should_log = false;
RGWRESTMgr *mgr;
- RGWHandler_REST *handler = rest->get_handler(store, s, client_io, &mgr,
- &init_error);
+ RGWHandler_REST *handler = rest->get_handler(store, s, frontend_prefix,
+ client_io, &mgr, &init_error);
if (init_error != 0) {
abort_early(s, NULL, init_error, NULL);
goto done;
RGWREST* rest;
RGWFrontendConfig* conf;
int sock_fd;
+ std::string uri_prefix;
struct RGWWQ : public ThreadPool::WorkQueue<RGWRequest> {
RGWProcess* process;
} req_wq;
public:
- RGWProcess(CephContext* cct, RGWProcessEnv* pe, int num_threads,
- RGWFrontendConfig* _conf)
- : cct(cct), store(pe->store), olog(pe->olog),
+ RGWProcess(CephContext* const cct,
+ RGWProcessEnv* const pe,
+ const int num_threads,
+ RGWFrontendConfig* const conf)
+ : cct(cct),
+ store(pe->store),
+ olog(pe->olog),
m_tp(cct, "RGWProcess::m_tp", "tp_rgw_process", num_threads),
req_throttle(cct, "rgw_ops", num_threads * 2),
- rest(pe->rest), conf(_conf), sock_fd(-1),
+ rest(pe->rest),
+ conf(conf),
+ sock_fd(-1),
+ uri_prefix(pe->uri_prefix),
req_wq(this, g_conf->rgw_op_thread_timeout,
- g_conf->rgw_op_thread_suicide_timeout, &m_tp) {}
+ g_conf->rgw_op_thread_suicide_timeout, &m_tp) {
+ }
- virtual ~RGWProcess() {}
+ virtual ~RGWProcess() = default;
virtual void run() = 0;
virtual void handle_request(RGWRequest *req) = 0;
class RGWFCGXProcess : public RGWProcess {
int max_connections;
- std::string uri_prefix;
public:
/* have a bit more connections than threads so that requests are
RGWFCGXProcess(CephContext* const cct,
RGWProcessEnv* const pe,
const int num_threads,
- RGWFrontendConfig* const _conf)
- : RGWProcess(cct, pe, num_threads, _conf),
- max_connections(num_threads + (num_threads >> 3)),
- /* We shouldn't mess with our parents by std::moving here. */
- uri_prefix(pe->uri_prefix)
- {}
+ RGWFrontendConfig* const conf)
+ : RGWProcess(cct, pe, num_threads, conf),
+ max_connections(num_threads + (num_threads >> 3)) {
+ }
void run();
void handle_request(RGWRequest* req);
extern int process_request(RGWRados* store,
RGWREST* rest,
RGWRequest* req,
- RGWRestfulIO* client_io,
+ const std::string& frontend_prefix,
+ RGWRestfulIO* client_io,
OpsLogSocket* olog);
extern int rgw_process_authenticated(RGWHandler_REST* handler,
default_mgr = mgr;
}
-RGWRESTMgr *RGWRESTMgr::get_resource_mgr(struct req_state *s, const string& uri, string *out_uri)
+RGWRESTMgr* RGWRESTMgr::get_resource_mgr(struct req_state* const s,
+ const std::string& uri,
+ std::string* const out_uri)
{
*out_uri = uri;
if (uri.compare(0, iter->first, resource) == 0 &&
(uri.size() == iter->first ||
uri[iter->first] == '/')) {
- string suffix = uri.substr(iter->first);
+ std::string suffix = uri.substr(iter->first);
return resource_mgrs[resource]->get_resource_mgr(s, suffix, out_uri);
}
}
return 0;
}
-RGWHandler_REST* RGWREST::get_handler(RGWRados *store, struct req_state *s,
- RGWRestfulIO *rio, RGWRESTMgr **pmgr,
- int *init_error)
+RGWHandler_REST* RGWREST::get_handler(RGWRados * const store,
+ struct req_state* const s,
+ const std::string& frontend_prefix,
+ RGWRestfulIO* const rio,
+ RGWRESTMgr** const pmgr,
+ int* const init_error)
{
- RGWHandler_REST* handler;
-
*init_error = preprocess(s, rio);
- if (*init_error < 0)
- return NULL;
+ if (*init_error < 0) {
+ return nullptr;
+ }
- RGWRESTMgr *m = mgr.get_resource_mgr(s, s->decoded_uri, &s->relative_uri);
- if (!m) {
+ RGWRESTMgr *m = mgr.get_manager(s, frontend_prefix, s->decoded_uri,
+ &s->relative_uri);
+ if (! m) {
*init_error = -ERR_METHOD_NOT_ALLOWED;
- return NULL;
+ return nullptr;
}
- if (pmgr)
+ if (pmgr) {
*pmgr = m;
+ }
- handler = m->get_handler(s);
- if (!handler) {
+ RGWHandler_REST* handler = m->get_handler(s, frontend_prefix);
+ if (! handler) {
*init_error = -ERR_METHOD_NOT_ALLOWED;
return NULL;
}
*init_error = handler->init(store, s, rio);
if (*init_error < 0) {
m->put_handler(handler);
- return NULL;
+ return nullptr;
}
return handler;
std::multimap<size_t, std::string> resources_by_size;
RGWRESTMgr* default_mgr;
+ virtual RGWRESTMgr* get_resource_mgr(struct req_state* s,
+ const std::string& uri,
+ std::string* out_uri);
+
+ virtual RGWRESTMgr* get_resource_mgr_as_default(struct req_state* const s,
+ const std::string& uri,
+ std::string* our_uri) {
+ return this;
+ }
+
public:
RGWRESTMgr()
: should_log(false),
}
virtual ~RGWRESTMgr();
- void register_resource(string resource, RGWRESTMgr *mgr);
- void register_default_mgr(RGWRESTMgr *mgr);
+ void register_resource(std::string resource, RGWRESTMgr* mgr);
+ void register_default_mgr(RGWRESTMgr* mgr);
- virtual RGWRESTMgr* get_resource_mgr(struct req_state *s,
- const std::string& uri,
- std::string* out_uri);
+ virtual RGWRESTMgr* get_manager(struct req_state* const s,
+ /* Prefix to be concatenated with @uri
+ * during the lookup. */
+ const std::string& frontend_prefix,
+ const std::string& uri,
+ std::string* out_uri) final {
+ return get_resource_mgr(s, frontend_prefix + uri, out_uri);
+ }
- virtual RGWRESTMgr* get_resource_mgr_as_default(struct req_state* s,
- const std::string& uri,
- std::string* our_uri) {
- return this;
+ virtual RGWHandler_REST* get_handler(struct req_state* const s,
+ const std::string& frontend_prefix) {
+ return nullptr;
}
- virtual RGWHandler_REST *get_handler(struct req_state *s) { return NULL; }
- virtual void put_handler(RGWHandler_REST *handler) { delete handler; }
+ virtual void put_handler(RGWHandler_REST* const handler) {
+ delete handler;
+ }
+
+ void set_logging(bool _should_log) {
+ should_log = _should_log;
+ }
- void set_logging(bool _should_log) { should_log = _should_log; }
- bool get_logging() { return should_log; }
+ bool get_logging() const {
+ return should_log;
+ }
};
class RGWLibIO;
RGWREST() {}
RGWHandler_REST *get_handler(RGWRados *store,
struct req_state *s,
+ const std::string& frontend_prefix,
RGWRestfulIO *rio,
RGWRESTMgr **pmgr,
int *init_error);
class RGWRESTMgr_Bucket : public RGWRESTMgr {
public:
- RGWRESTMgr_Bucket() {}
- virtual ~RGWRESTMgr_Bucket() {}
+ RGWRESTMgr_Bucket() = default;
+ virtual ~RGWRESTMgr_Bucket() = default;
- RGWHandler_REST* get_handler(struct req_state *s) {
+ RGWHandler_REST* get_handler(struct req_state*,
+ const std::string&) override {
return new RGWHandler_Bucket;
}
};
class RGWRESTMgr_Config : public RGWRESTMgr {
public:
- RGWRESTMgr_Config() {}
- virtual ~RGWRESTMgr_Config() {}
+ RGWRESTMgr_Config() = default;
+ virtual ~RGWRESTMgr_Config() = default;
- virtual RGWHandler_REST* get_handler(struct req_state *s){
+ RGWHandler_REST* get_handler(struct req_state*,
+ const std::string&) override {
return new RGWHandler_Config;
}
};
class RGWRESTMgr_Log : public RGWRESTMgr {
public:
- RGWRESTMgr_Log() {}
- virtual ~RGWRESTMgr_Log() {}
+ RGWRESTMgr_Log() = default;
+ virtual ~RGWRESTMgr_Log() = default;
- virtual RGWHandler_REST* get_handler(struct req_state *s){
+ RGWHandler_REST* get_handler(struct req_state* const,
+ const std::string& frontend_prefixs) override {
return new RGWHandler_Log;
}
};
class RGWRESTMgr_Metadata : public RGWRESTMgr {
public:
- RGWRESTMgr_Metadata() {}
- virtual ~RGWRESTMgr_Metadata() {}
+ RGWRESTMgr_Metadata() = default;
+ virtual ~RGWRESTMgr_Metadata() = default;
- virtual RGWHandler_REST* get_handler(struct req_state *s){
+ RGWHandler_REST* get_handler(struct req_state* const s,
+ const std::string& frontend_prefix) override {
return new RGWHandler_Metadata;
}
};
class RGWRESTMgr_Opstate : public RGWRESTMgr {
public:
- RGWRESTMgr_Opstate() {}
- virtual ~RGWRESTMgr_Opstate() {}
+ RGWRESTMgr_Opstate() = default;
+ virtual ~RGWRESTMgr_Opstate() = default;
- virtual RGWHandler_REST* get_handler(struct req_state *s){
+ RGWHandler_REST* get_handler(struct req_state*,
+ const std::string&) override {
return new RGWHandler_Opstate;
}
};
class RGWRESTMgr_Period : public RGWRESTMgr {
public:
- RGWHandler_REST* get_handler(struct req_state*) override {
+ RGWHandler_REST* get_handler(struct req_state*,
+ const std::string&) override {
return new RGWHandler_Period;
}
};
register_resource("period", new RGWRESTMgr_Period);
}
-RGWHandler_REST* RGWRESTMgr_Realm::get_handler(struct req_state*)
+RGWHandler_REST* RGWRESTMgr_Realm::get_handler(struct req_state*,
+ const std::string&)
{
return new RGWHandler_Realm;
}
public:
RGWRESTMgr_Realm();
- RGWHandler_REST* get_handler(struct req_state*) override;
+ RGWHandler_REST* get_handler(struct req_state*,
+ const std::string&) override;
};
#endif
class RGWRESTMgr_ReplicaLog : public RGWRESTMgr {
public:
- RGWRESTMgr_ReplicaLog() {}
- virtual ~RGWRESTMgr_ReplicaLog() {}
+ RGWRESTMgr_ReplicaLog() = default;
+ virtual ~RGWRESTMgr_ReplicaLog() = default;
- virtual RGWHandler_REST* get_handler(struct req_state *s){
+ RGWHandler_REST* get_handler(struct req_state*,
+ const std::string&) override {
return new RGWHandler_ReplicaLog;
}
};
return RGWHandler_REST::init(store, state, cio);
}
-RGWHandler_REST* RGWRESTMgr_S3::get_handler(struct req_state *s)
+RGWHandler_REST* RGWRESTMgr_S3::get_handler(struct req_state* const s,
+ const std::string& frontend_prefix)
{
bool is_s3website = enable_s3website && (s->prot_flags & RGW_REST_WEBSITE);
int ret =
private:
bool enable_s3website;
public:
- explicit RGWRESTMgr_S3(bool _enable_s3website = false)
- : enable_s3website(_enable_s3website)
- {}
+ explicit RGWRESTMgr_S3(bool enable_s3website = false)
+ : enable_s3website(enable_s3website) {
+ }
- virtual ~RGWRESTMgr_S3() {}
+ virtual ~RGWRESTMgr_S3() = default;
- virtual RGWHandler_REST *get_handler(struct req_state *s);
+ RGWHandler_REST *get_handler(struct req_state* s,
+ const std::string& frontend_prefix) override;
};
class RGWHandler_REST_Obj_S3Website;
}
}
-int RGWHandler_REST_SWIFT::init_from_header(struct req_state *s)
+int RGWHandler_REST_SWIFT::init_from_header(struct req_state* const s,
+ const std::string& frontend_prefix)
{
string req;
string first;
s->prot_flags |= RGW_REST_SWIFT;
- const char *req_name = s->decoded_uri.c_str();
+ char reqbuf[frontend_prefix.length() + s->decoded_uri.length() + 1];
+ sprintf(reqbuf, "%s%s", frontend_prefix.c_str(), s->decoded_uri.c_str());
+ const char *req_name = reqbuf;
+
const char *p;
if (*req_name == '?') {
g_conf->rgw_swift_url_prefix.c_str(), tenant_path.c_str());
}
- if (s->decoded_uri[0] != '/' ||
- s->decoded_uri.compare(0, blen, buf) != 0) {
+ if (strncmp(reqbuf, buf, blen) != 0) {
return -ENOENT;
}
return RGWHandler_REST::init(store, s, cio);
}
-RGWHandler_REST* RGWRESTMgr_SWIFT::get_handler(struct req_state *s)
+RGWHandler_REST* RGWRESTMgr_SWIFT::get_handler(struct req_state* const s,
+ const std::string& frontend_prefix)
{
- int ret = RGWHandler_REST_SWIFT::init_from_header(s);
- if (ret < 0)
- return NULL;
+ int ret = RGWHandler_REST_SWIFT::init_from_header(s, frontend_prefix);
+ if (ret < 0) {
+ ldout(s->cct, 10) << "init_from_header returned err=" << ret << dendl;
+ return nullptr;
+ }
- if (s->init_state.url_bucket.empty())
+ if (s->init_state.url_bucket.empty()) {
return new RGWHandler_REST_Service_SWIFT;
+ }
if (s->object.empty()) {
return new RGWHandler_REST_Bucket_SWIFT;
return new RGWHandler_REST_Obj_SWIFT;
}
-RGWHandler_REST* RGWRESTMgr_SWIFT_Info::get_handler(struct req_state *s)
+RGWHandler_REST* RGWRESTMgr_SWIFT_Info::get_handler(
+ struct req_state* const s,
+ const std::string& frontend_prefix)
{
s->prot_flags |= RGW_REST_SWIFT;
return new RGWHandler_REST_SWIFT_Info;
return false;
}
- static int init_from_header(struct req_state *s);
+ static int init_from_header(struct req_state* s,
+ const std::string& frontend_prefix);
public:
RGWHandler_REST_SWIFT() {}
virtual ~RGWHandler_REST_SWIFT() {}
};
class RGWRESTMgr_SWIFT : public RGWRESTMgr {
-public:
- RGWRESTMgr_SWIFT() {}
- virtual ~RGWRESTMgr_SWIFT() {}
-
- RGWHandler_REST *get_handler(struct req_state *s) override;
-
- RGWRESTMgr* get_resource_mgr_as_default(struct req_state* s,
+protected:
+ RGWRESTMgr* get_resource_mgr_as_default(struct req_state* const s,
const std::string& uri,
- std::string* out_uri) override {
+ std::string* const out_uri) override {
return this->get_resource_mgr(s, uri, out_uri);
}
+
+public:
+ RGWRESTMgr_SWIFT() = default;
+ virtual ~RGWRESTMgr_SWIFT() = default;
+
+ RGWHandler_REST *get_handler(struct req_state *s,
+ const std::string& frontend_prefix) override;
};
};
class RGWRESTMgr_SWIFT_CrossDomain : public RGWRESTMgr {
-public:
- RGWRESTMgr_SWIFT_CrossDomain() = default;
- ~RGWRESTMgr_SWIFT_CrossDomain() = default;
-
+protected:
RGWRESTMgr *get_resource_mgr(struct req_state* const s,
const std::string& uri,
std::string* const out_uri) override {
return this;
}
- RGWHandler_REST* get_handler(struct req_state* const s) override {
+public:
+ RGWRESTMgr_SWIFT_CrossDomain() = default;
+ ~RGWRESTMgr_SWIFT_CrossDomain() = default;
+
+ RGWHandler_REST* get_handler(struct req_state* const s,
+ const std::string&) override {
s->prot_flags |= RGW_REST_SWIFT;
return new RGWHandler_SWIFT_CrossDomain;
}
};
class RGWRESTMgr_SWIFT_HealthCheck : public RGWRESTMgr {
-public:
- RGWRESTMgr_SWIFT_HealthCheck() = default;
- ~RGWRESTMgr_SWIFT_HealthCheck() = default;
-
+protected:
RGWRESTMgr *get_resource_mgr(struct req_state* const s,
const std::string& uri,
std::string* const out_uri) override {
return this;
}
- RGWHandler_REST* get_handler(struct req_state* const s) override {
+public:
+ RGWRESTMgr_SWIFT_HealthCheck() = default;
+ ~RGWRESTMgr_SWIFT_HealthCheck() = default;
+
+ RGWHandler_REST* get_handler(struct req_state* const s,
+ const std::string&) override {
s->prot_flags |= RGW_REST_SWIFT;
return new RGWHandler_SWIFT_HealthCheck;
}
public:
RGWRESTMgr_SWIFT_Info() = default;
virtual ~RGWRESTMgr_SWIFT_Info() = default;
- virtual RGWHandler_REST *get_handler(struct req_state *s) override;
+
+ RGWHandler_REST *get_handler(struct req_state* s,
+ const std::string& frontend_prefix) override;
};
#endif
class RGWRESTMgr_Usage : public RGWRESTMgr {
public:
- RGWRESTMgr_Usage() {}
- virtual ~RGWRESTMgr_Usage() {}
+ RGWRESTMgr_Usage() = default;
+ virtual ~RGWRESTMgr_Usage() = default;
- RGWHandler_REST* get_handler(struct req_state *s) {
+ RGWHandler_REST* get_handler(struct req_state*,
+ const std::string&) override {
return new RGWHandler_Usage;
}
};
class RGWRESTMgr_User : public RGWRESTMgr {
public:
- RGWRESTMgr_User() {}
- virtual ~RGWRESTMgr_User() {}
+ RGWRESTMgr_User() = default;
+ virtual ~RGWRESTMgr_User() = default;
- RGWHandler_REST *get_handler(struct req_state *s) {
+ RGWHandler_REST *get_handler(struct req_state*,
+ const std::string&) override {
return new RGWHandler_User;
}
};
class RGWRESTMgr_SWIFT_Auth : public RGWRESTMgr {
public:
- RGWRESTMgr_SWIFT_Auth() {}
- virtual ~RGWRESTMgr_SWIFT_Auth() {}
+ RGWRESTMgr_SWIFT_Auth() = default;
+ virtual ~RGWRESTMgr_SWIFT_Auth() = default;
- virtual RGWRESTMgr *get_resource_mgr(struct req_state *s, const string& uri, string *out_uri) {
+ virtual RGWRESTMgr *get_resource_mgr(struct req_state* const s,
+ const std::string& uri,
+ std::string* const out_uri) override {
return this;
}
- virtual RGWHandler_REST* get_handler(struct req_state *s) {
+
+ virtual RGWHandler_REST* get_handler(struct req_state*,
+ const std::string&) override {
return new RGWHandler_SWIFT_Auth;
}
};