]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
rgw: fix the subdir without slash of s3 website url 15703/head
authorliuhong <liuhong@cmss.chinamobile.com>
Thu, 15 Jun 2017 07:28:23 +0000 (15:28 +0800)
committerliuhong <liuhong@cmss.chinamobile.com>
Thu, 29 Jun 2017 02:25:05 +0000 (10:25 +0800)
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 <liuhong@cmss.chinamobile.com>
src/rgw/rgw_rest_s3.cc
src/rgw/rgw_rest_s3website.h
src/rgw/rgw_website.cc
src/rgw/rgw_website.h

index 1cca4cc83713ed387a82d8f253b6bf9204aa8fe0..5314b48b62976f9c58120252270c856cd5eadfb8 100644 (file)
@@ -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<RGWObjectCtx *>(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;
 
index 3a87c5eefd9e652a56145c180c53b1a539cc059c..abfe7b1984ad8777395b13054f63db28ca031c93 100644 (file)
@@ -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
index 62f48e19700528338b2ee5771b4d6f5050a15e4b..a80b7fff7dbc2180b6663c33de72876fba06f551 100644 (file)
@@ -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;
   }
index 8e2622b6e4e65487359565fb060cb38bb175c97e..fde29ad6ba963acc54712114318598ae5f4fd289 100644 (file)
@@ -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;