diff options
author | Yehuda Sadeh <yehuda@inktank.com> | 2013-06-14 18:20:41 -0700 |
---|---|---|
committer | Yehuda Sadeh <yehuda@inktank.com> | 2013-06-14 18:20:41 -0700 |
commit | d5679d045d5bcb33486bf57ed298d7fe58b021b5 (patch) | |
tree | 670fd9ad18ea740f7b8a8ed31a7ac84ae58ec68b | |
parent | 5ff2059758bdf625e7cf194224a8c67b52a45892 (diff) | |
download | ceph-d5679d045d5bcb33486bf57ed298d7fe58b021b5.tar.gz |
rgw: forward amz headers of copy request to remote rgw
So that if request has any special conditions, it'll be processed
on the remote gateway
Signed-off-by: Yehuda Sadeh <yehuda@inktank.com>
-rw-r--r-- | src/rgw/rgw_common.cc | 4 | ||||
-rw-r--r-- | src/rgw/rgw_common.h | 2 | ||||
-rw-r--r-- | src/rgw/rgw_op.cc | 1 | ||||
-rw-r--r-- | src/rgw/rgw_rados.cc | 3 | ||||
-rw-r--r-- | src/rgw/rgw_rados.h | 1 | ||||
-rw-r--r-- | src/rgw/rgw_rest_client.cc | 9 | ||||
-rw-r--r-- | src/rgw/rgw_rest_client.h | 2 | ||||
-rw-r--r-- | src/rgw/rgw_rest_conn.cc | 20 | ||||
-rw-r--r-- | src/rgw/rgw_rest_conn.h | 2 |
9 files changed, 34 insertions, 10 deletions
diff --git a/src/rgw/rgw_common.cc b/src/rgw/rgw_common.cc index 45c63c3c470..1f31981a760 100644 --- a/src/rgw/rgw_common.cc +++ b/src/rgw/rgw_common.cc @@ -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) diff --git a/src/rgw/rgw_common.h b/src/rgw/rgw_common.h index 148623c6677..49f61d5a2b8 100644 --- a/src/rgw/rgw_common.h +++ b/src/rgw/rgw_common.h @@ -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*/ diff --git a/src/rgw/rgw_op.cc b/src/rgw/rgw_op.cc index 0bf33a931f3..0c24533b4c3 100644 --- a/src/rgw/rgw_op.cc +++ b/src/rgw/rgw_op.cc @@ -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, diff --git a/src/rgw/rgw_rados.cc b/src/rgw/rgw_rados.cc index e12fd4ff583..d56559892ff 100644 --- a/src/rgw/rgw_rados.cc +++ b/src/rgw/rgw_rados.cc @@ -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; diff --git a/src/rgw/rgw_rados.h b/src/rgw/rgw_rados.h index 7c9dcfd0f89..06b9c91c387 100644 --- a/src/rgw/rgw_rados.h +++ b/src/rgw/rgw_rados.h @@ -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, diff --git a/src/rgw/rgw_rest_client.cc b/src/rgw/rgw_rest_client.cc index b8ee5aed8d6..f7479effa76 100644 --- a/src/rgw/rgw_rest_client.cc +++ b/src/rgw/rgw_rest_client.cc @@ -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; diff --git a/src/rgw/rgw_rest_client.h b/src/rgw/rgw_rest_client.h index 2d1d0d1db53..b709fd49a1a 100644 --- a/src/rgw/rgw_rest_client.h +++ b/src/rgw/rgw_rest_client.h @@ -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; } diff --git a/src/rgw/rgw_rest_conn.cc b/src/rgw/rgw_rest_conn.cc index 1cd57b40acf..943d5217f13 100644 --- a/src/rgw/rgw_rest_conn.cc +++ b/src/rgw/rgw_rest_conn.cc @@ -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, ¶ms); - 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, diff --git a/src/rgw/rgw_rest_conn.h b/src/rgw/rgw_rest_conn.h index a1b2a07286e..27e37fb2440 100644 --- a/src/rgw/rgw_rest_conn.h +++ b/src/rgw/rgw_rest_conn.h @@ -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); }; |