From: liuhong Date: Thu, 15 Jun 2017 07:28:23 +0000 (+0800) Subject: rgw: fix the subdir without slash of s3 website url X-Git-Tag: v12.1.1~127^2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=e817e22705ac4f6935cd2b1510446059e69b2499;p=ceph.git rgw: fix the subdir without slash of s3 website url if we use the subdir without slash, we cannot visit the default index.html, which we configured.It is not consistent with AWS S3. Fixes: http://tracker.ceph.com/issues/20307 Signed-off-by: liuhong --- diff --git a/src/rgw/rgw_rest_s3.cc b/src/rgw/rgw_rest_s3.cc index 1cca4cc83713..5314b48b6297 100644 --- a/src/rgw/rgw_rest_s3.cc +++ b/src/rgw/rgw_rest_s3.cc @@ -3222,6 +3222,31 @@ RGWHandler_REST* RGWRESTMgr_S3::get_handler(struct req_state* const s, return handler; } +bool RGWHandler_REST_S3Website::web_dir() const { + std::string subdir_name = url_decode(s->object.name); + + if (subdir_name.empty()) { + return false; + } else if (subdir_name.back() == '/') { + subdir_name.pop_back(); + } + + rgw_obj obj(s->bucket, subdir_name); + + RGWObjectCtx& obj_ctx = *static_cast(s->obj_ctx); + obj_ctx.obj.set_atomic(obj); + obj_ctx.obj.set_prefetch_data(obj); + + RGWObjState* state = nullptr; + if (store->get_obj_state(&obj_ctx, s->bucket_info, obj, &state, false) < 0) { + return false; + } + if (! state->exists) { + return false; + } + return state->exists; +} + int RGWHandler_REST_S3Website::retarget(RGWOp* op, RGWOp** new_op) { *new_op = op; ldout(s->cct, 10) << __func__ << "Starting retarget" << dendl; @@ -3243,7 +3268,7 @@ int RGWHandler_REST_S3Website::retarget(RGWOp* op, RGWOp** new_op) { } rgw_obj_key new_obj; - s->bucket_info.website_conf.get_effective_key(s->object.name, &new_obj.name); + s->bucket_info.website_conf.get_effective_key(s->object.name, &new_obj.name, web_dir()); ldout(s->cct, 10) << "retarget get_effective_key " << s->object << " -> " << new_obj << dendl; diff --git a/src/rgw/rgw_rest_s3website.h b/src/rgw/rgw_rest_s3website.h index 3a87c5eefd9e..abfe7b1984ad 100644 --- a/src/rgw/rgw_rest_s3website.h +++ b/src/rgw/rgw_rest_s3website.h @@ -17,6 +17,7 @@ #include "rgw_rest_s3.h" class RGWHandler_REST_S3Website : public RGWHandler_REST_S3 { + bool web_dir() const; protected: int retarget(RGWOp *op, RGWOp **new_op) override; // TODO: this should be virtual I think, and ensure that it's always diff --git a/src/rgw/rgw_website.cc b/src/rgw/rgw_website.cc index 62f48e197005..a80b7fff7dbc 100644 --- a/src/rgw/rgw_website.cc +++ b/src/rgw/rgw_website.cc @@ -106,13 +106,15 @@ bool RGWBucketWebsiteConf::should_redirect(const string& key, const int http_err return true; } -void RGWBucketWebsiteConf::get_effective_key(const string& key, string *effective_key) const +void RGWBucketWebsiteConf::get_effective_key(const string& key, string *effective_key, bool is_file) const { if (key.empty()) { *effective_key = index_doc_suffix; } else if (key[key.size() - 1] == '/') { *effective_key = key + index_doc_suffix; + } else if (! is_file) { + *effective_key = key + "/" + index_doc_suffix; } else { *effective_key = key; } diff --git a/src/rgw/rgw_website.h b/src/rgw/rgw_website.h index 8e2622b6e4e6..fde29ad6ba96 100644 --- a/src/rgw/rgw_website.h +++ b/src/rgw/rgw_website.h @@ -210,7 +210,7 @@ struct RGWBucketWebsiteConf RGWBWRoutingRule *redirect); void get_effective_key(const std::string& key, - std::string *effective_key) const; + std::string *effective_key, bool is_file) const; const std::string& get_index_doc() const { return index_doc_suffix;