]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
rgw: forward amz headers of copy request to remote rgw
authorYehuda Sadeh <yehuda@inktank.com>
Sat, 15 Jun 2013 01:20:41 +0000 (18:20 -0700)
committerYehuda Sadeh <yehuda@inktank.com>
Sat, 15 Jun 2013 01:20:41 +0000 (18:20 -0700)
So that if request has any special conditions, it'll be processed
on the remote gateway

Signed-off-by: Yehuda Sadeh <yehuda@inktank.com>
src/rgw/rgw_common.cc
src/rgw/rgw_common.h
src/rgw/rgw_op.cc
src/rgw/rgw_rados.cc
src/rgw/rgw_rados.h
src/rgw/rgw_rest_client.cc
src/rgw/rgw_rest_client.h
src/rgw/rgw_rest_conn.cc
src/rgw/rgw_rest_conn.h

index 45c63c3c470f41e9fc0b8d5e5835f772e5e94d34..1f31981a760cfee6697ea6400fb2b65938c1d77d 100644 (file)
@@ -178,7 +178,7 @@ struct str_len meta_prefixes[] = { STR_LEN_ENTRY("HTTP_X_AMZ"),
                                    {NULL, 0} };
 
 
-int req_info::init_meta_info(bool *found_bad_meta)
+void req_info::init_meta_info(bool *found_bad_meta)
 {
   x_meta_map.clear();
 
@@ -228,8 +228,6 @@ int req_info::init_meta_info(bool *found_bad_meta)
   for (iter = x_meta_map.begin(); iter != x_meta_map.end(); ++iter) {
     dout(10) << "x>> " << iter->first << ":" << iter->second << dendl;
   }
-
-  return 0;
 }
 
 std::ostream& operator<<(std::ostream& oss, const rgw_err &err)
index 148623c6677d7fdd87b52665a0aa9dc85c65fbb1..49f61d5a2b88c6403fca649b9f4f2e0a0012620f 100644 (file)
@@ -686,7 +686,7 @@ struct req_info {
 
   req_info(CephContext *cct, RGWEnv *_env);
   void rebuild_from(req_info& src);
-  int init_meta_info(bool *found_nad_meta);
+  void init_meta_info(bool *found_nad_meta);
 };
 
 /** Store all the state necessary to complete and respond to an HTTP request*/
index 0bf33a931f31eb4e8fbcc9ad02ca26784fc49d89..0c24533b4c3fc30fd9ffebf1bd08b8375303cbdf 100644 (file)
@@ -1557,6 +1557,7 @@ void RGWCopyObj::execute()
 
   ret = store->copy_obj(s->obj_ctx,
                         s->user.user_id,
+                        &s->info,
                         dst_obj,
                         src_obj,
                         dest_bucket_info,
index e12fd4ff5839a5fd57bcf04730393eb956ccc438..d56559892fffb9e9f1af374ee89c2115e71dc2a2 100644 (file)
@@ -2175,6 +2175,7 @@ static void set_copy_attrs(map<string, bufferlist>& src_attrs, map<string, buffe
  */
 int RGWRados::copy_obj(void *ctx,
                const string& user_id,
+               req_info *info,
                rgw_obj& dest_obj,
                rgw_obj& src_obj,
                RGWBucketInfo& dest_bucket_info,
@@ -2240,7 +2241,7 @@ int RGWRados::copy_obj(void *ctx,
 
     RGWRadosPutObj cb(&processor);
   
-    int ret = rest_conn->get_obj(user_id, src_obj, true, &cb, &in_stream_req);
+    int ret = rest_conn->get_obj(user_id, info, src_obj, true, &cb, &in_stream_req);
     if (ret < 0)
       return ret;
 
index 7c9dcfd0f89f03d1858df76fd1e547511135732b..06b9c91c3871f3c88981fbafc87f56806b61c6f8 100644 (file)
@@ -890,6 +890,7 @@ public:
    */
   virtual int copy_obj(void *ctx,
                const string& user_id,
+               req_info *info,
                rgw_obj& dest_obj,
                rgw_obj& src_obj,
                RGWBucketInfo& dest_bucket_info,
index b8ee5aed8d60ce84623b0d53f1a2a65e09de1466..f7479effa765bf2b2780114cdbc698af60c21cad 100644 (file)
@@ -531,7 +531,7 @@ int RGWRESTStreamWriteRequest::complete(string& etag, time_t *mtime)
   return status;
 }
 
-int RGWRESTStreamReadRequest::get_obj(RGWAccessKey& key, rgw_obj& obj)
+int RGWRESTStreamReadRequest::get_obj(RGWAccessKey& key, map<string, string>& extra_headers, rgw_obj& obj)
 {
   string resource = obj.bucket.name + "/" + obj.object;
   string new_url = url;
@@ -552,12 +552,19 @@ int RGWRESTStreamReadRequest::get_obj(RGWAccessKey& key, rgw_obj& obj)
 
   new_env.set("HTTP_DATE", date_str.c_str());
 
+  for (map<string, string>::iterator iter = extra_headers.begin();
+       iter != extra_headers.end(); ++iter) {
+    new_env.set(iter->first.c_str(), iter->second.c_str());
+  }
+
   new_info.method = "GET";
 
   new_info.script_uri = "/";
   new_info.script_uri.append(resource);
   new_info.request_uri = new_info.script_uri;
 
+  new_info.init_meta_info(NULL);
+
   int ret = sign_request(key, new_env, new_info);
   if (ret < 0) {
     ldout(cct, 0) << "ERROR: failed to sign request" << dendl;
index 2d1d0d1db537e60e22583cb727d743ffe6290175..b709fd49a1aa8d4ee0ef535e2367812f9aee984c 100644 (file)
@@ -90,7 +90,7 @@ public:
                 lock("RGWRESTStreamReadRequest"), cb(_cb),
                 chunk_ofs(0), ofs(0) {}
   ~RGWRESTStreamReadRequest() {}
-  int get_obj(RGWAccessKey& key, rgw_obj& obj);
+  int get_obj(RGWAccessKey& key, map<string, string>& extra_headers, rgw_obj& obj);
   int complete(string& etag, time_t *mtime, map<string, string>& attrs);
 
   void set_in_cb(RGWGetDataCB *_cb) { cb = _cb; }
index 1cd57b40acf7c04def9b1c0a5a9659b167922817..943d5217f133e251b80633e3f9877205c7fd2106 100644 (file)
@@ -69,7 +69,8 @@ int RGWRegionConnection::complete_request(RGWRESTStreamWriteRequest *req, string
   return ret;
 }
 
-int RGWRegionConnection::get_obj(const string& uid, rgw_obj& obj, bool prepend_metadata, RGWGetDataCB *cb, RGWRESTStreamReadRequest **req)
+int RGWRegionConnection::get_obj(const string& uid, req_info *info /* optional */, rgw_obj& obj, bool prepend_metadata,
+                                 RGWGetDataCB *cb, RGWRESTStreamReadRequest **req)
 {
   string url;
   int ret = get_url(url);
@@ -83,7 +84,22 @@ int RGWRegionConnection::get_obj(const string& uid, rgw_obj& obj, bool prepend_m
     params.push_back(make_pair<string, string>(RGW_SYS_PARAM_PREFIX "prepend-metadata", region));
   }
   *req = new RGWRESTStreamReadRequest(cct, url, cb, NULL, &params);
-  return (*req)->get_obj(key, obj);
+  map<string, string> extra_headers;
+  if (info) {
+    map<string, string>& orig_map = info->env->get_map();
+
+    /* add original headers that start with HTTP_X_AMZ_ */
+#define SEARCH_AMZ_PREFIX "HTTP_X_AMZ_"
+    for (map<string, string>::iterator iter = orig_map.lower_bound(SEARCH_AMZ_PREFIX); iter != orig_map.end(); ++iter) {
+      const string& name = iter->first;
+      if (name == "HTTP_X_AMZ_DATE") /* dont forward date from original request */
+        continue;
+      if (name.compare(0, sizeof(SEARCH_AMZ_PREFIX) - 1, "HTTP_X_AMZ_") != 0)
+        break;
+      extra_headers[iter->first] = iter->second;
+    }
+  }
+  return (*req)->get_obj(key, extra_headers, obj);
 }
 
 int RGWRegionConnection::complete_request(RGWRESTStreamReadRequest *req, string& etag, time_t *mtime,
index a1b2a07286e17236a81f0018ebb8fec203357ee3..27e37fb24408ef2cdfe8558c3e36873b11075e5b 100644 (file)
@@ -28,7 +28,7 @@ public:
                    map<string, bufferlist>& attrs, RGWRESTStreamWriteRequest **req);
   int complete_request(RGWRESTStreamWriteRequest *req, string& etag, time_t *mtime);
 
-  int get_obj(const string& uid, rgw_obj& obj, bool prepend_metadata, RGWGetDataCB *cb, RGWRESTStreamReadRequest **req);
+  int get_obj(const string& uid, req_info *info /* optional */, rgw_obj& obj, bool prepend_metadata, RGWGetDataCB *cb, RGWRESTStreamReadRequest **req);
   int complete_request(RGWRESTStreamReadRequest *req, string& etag, time_t *mtime,
                        map<string, string>& attrs);
 };