From: Soumya Koduri Date: Wed, 23 Jun 2021 15:46:24 +0000 (+0530) Subject: rgw/RGWRESTConn: Define a wrapper to send PUT/POST stream request X-Git-Tag: v17.1.0~411^2~1 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=1e48366c7bc9610abceb4b91377807a67935886e;p=ceph.git rgw/RGWRESTConn: Define a wrapper to send PUT/POST stream request Similar to "get_resource()", add an API "send_resource()" to send PUT/POST/DELETE Stream request on RGWRestConn Signed-off-by: Soumya Koduri --- diff --git a/src/rgw/rgw_rest_client.h b/src/rgw/rgw_rest_client.h index 4ffdb2cfe8eb..7214babb9b9c 100644 --- a/src/rgw/rgw_rest_client.h +++ b/src/rgw/rgw_rest_client.h @@ -219,6 +219,14 @@ public: param_vec_t *_params, std::optional _api_name) : RGWRESTStreamRWRequest(_cct, "HEAD", _url, _cb, _headers, _params, _api_name) {} }; +class RGWRESTStreamSendRequest : public RGWRESTStreamRWRequest { +public: + RGWRESTStreamSendRequest(CephContext *_cct, const string& method, const string& _url, + ReceiveCB *_cb, param_vec_t *_headers, param_vec_t *_params, + std::optional _api_name, + HostStyle _host_style = PathStyle) : RGWRESTStreamRWRequest(_cct, method, _url, _cb, _headers, _params, _api_name, _host_style) {} +}; + class RGWRESTStreamS3PutObj : public RGWHTTPStreamRWRequest { std::optional api_name; HostStyle host_style; diff --git a/src/rgw/rgw_rest_conn.cc b/src/rgw/rgw_rest_conn.cc index ff966d6ff3f7..726bc58a5aaa 100644 --- a/src/rgw/rgw_rest_conn.cc +++ b/src/rgw/rgw_rest_conn.cc @@ -376,6 +376,42 @@ int RGWRESTConn::get_resource(const DoutPrefixProvider *dpp, return req.complete_request(y); } +int RGWRESTConn::send_resource(const DoutPrefixProvider *dpp, const string& method, + const string& resource, rgw_http_param_pair *extra_params, + map *extra_headers, bufferlist& bl, + bufferlist *send_data, RGWHTTPManager *mgr, optional_yield y) +{ + string url; + int ret = get_url(url); + if (ret < 0) + return ret; + + param_vec_t params; + + if (extra_params) { + params = make_param_list(extra_params); + } + + populate_params(params, nullptr, self_zone_group); + + RGWStreamIntoBufferlist cb(bl); + + RGWRESTStreamSendRequest req(cct, method, url, &cb, NULL, ¶ms, api_name, host_style); + + map headers; + if (extra_headers) { + headers.insert(extra_headers->begin(), extra_headers->end()); + } + + ret = req.send_request(dpp, &key, headers, resource, mgr, send_data); + if (ret < 0) { + ldpp_dout(dpp, 5) << __func__ << ": send_request() resource=" << resource << " returned ret=" << ret << dendl; + return ret; + } + + return req.complete_request(y); +} + RGWRESTReadResource::RGWRESTReadResource(RGWRESTConn *_conn, const string& _resource, const rgw_http_param_pair *pp, diff --git a/src/rgw/rgw_rest_conn.h b/src/rgw/rgw_rest_conn.h index e0e1b12abe5d..0dfd0c7415c1 100644 --- a/src/rgw/rgw_rest_conn.h +++ b/src/rgw/rgw_rest_conn.h @@ -200,6 +200,16 @@ public: RGWHTTPManager *mgr, optional_yield y); + int send_resource(const DoutPrefixProvider *dpp, + const string& method, + const string& resource, + rgw_http_param_pair *extra_params, + map* extra_headers, + bufferlist& bl, + bufferlist *send_data, + RGWHTTPManager *mgr, + optional_yield y); + template int get_json_resource(const DoutPrefixProvider *dpp, const std::string& resource, param_vec_t *params, bufferlist *in_data, optional_yield y, T& t);