From: Abhishek Lekshmanan Date: Mon, 27 Mar 2017 13:04:30 +0000 (+0200) Subject: rgw_cr_rest: allow sending of raw put requests X-Git-Tag: v13.1.0~270^2~117 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=9262c93ffa012307749613e8637f041ea54dc374;p=ceph.git rgw_cr_rest: allow sending of raw put requests Modify SendRESTResourceCR to handle when we don't have a json formatted input class and send raw bufferlists instead. Signed-off-by: Abhishek Lekshmanan --- diff --git a/src/rgw/rgw_cr_rest.h b/src/rgw/rgw_cr_rest.h index de31ad0a36eb..165b4fa85a6f 100644 --- a/src/rgw/rgw_cr_rest.h +++ b/src/rgw/rgw_cr_rest.h @@ -84,46 +84,54 @@ public: } }; -template -class RGWSendRESTResourceCR : public RGWSimpleCoroutine { +template +class RGWSendRawRESTResourceCR: public RGWSimpleCoroutine { + protected: RGWRESTConn *conn; RGWHTTPManager *http_manager; string method; string path; param_vec_t params; T *result; - S input; + bufferlist input_bl; boost::intrusive_ptr http_op; -public: - RGWSendRESTResourceCR(CephContext *_cct, RGWRESTConn *_conn, - RGWHTTPManager *_http_manager, - const string& _method, const string& _path, - rgw_http_param_pair *_params, S& _input, T *_result) - : RGWSimpleCoroutine(_cct), conn(_conn), http_manager(_http_manager), - method(_method), path(_path), params(make_param_list(_params)), result(_result), - input(_input) - {} + public: + RGWSendRawRESTResourceCR(CephContext *_cct, RGWRESTConn *_conn, + RGWHTTPManager *_http_manager, + const string& _method, const string& _path, + rgw_http_param_pair *_params, bufferlist& _input, T *_result) + : RGWSimpleCoroutine(_cct), conn(_conn), http_manager(_http_manager), + method(_method), path(_path), params(make_param_list(_params)), result(_result), + input_bl(_input) + {} + + RGWSendRawRESTResourceCR(CephContext *_cct, RGWRESTConn *_conn, + RGWHTTPManager *_http_manager, + const string& _method, const string& _path, + rgw_http_param_pair *_params, T *_result) + : RGWSimpleCoroutine(_cct), conn(_conn), http_manager(_http_manager), + method(_method), path(_path), params(make_param_list(_params)), result(_result) + {} + + - ~RGWSendRESTResourceCR() override { + ~RGWSendRawRESTResourceCR() override { request_cleanup(); } + void set_input_bl(bufferlist bl){ + input_bl = std::move(bl); + } + int send_request() override { auto op = boost::intrusive_ptr( new RGWRESTSendResource(conn, method, path, params, NULL, http_manager)); op->set_user_info((void *)stack); - JSONFormatter jf; - encode_json("data", input, &jf); - std::stringstream ss; - jf.flush(ss); - bufferlist bl; - bl.append(ss.str()); - - int ret = op->aio_send(bl); + int ret = op->aio_send(input_bl); if (ret < 0) { lsubdout(cct, rgw, 0) << "ERROR: failed to send request" << dendl; op->put(); @@ -162,6 +170,26 @@ public: } }; +template +class RGWSendRESTResourceCR : public RGWSendRawRESTResourceCR { + public: + RGWSendRESTResourceCR(CephContext *_cct, RGWRESTConn *_conn, + RGWHTTPManager *_http_manager, + const string& _method, const string& _path, + rgw_http_param_pair *_params,S& _input, T *_result) + : RGWSendRawRESTResourceCR(_cct, _conn, _http_manager, _method, _path, _params, _result){ + + JSONFormatter jf; + encode_json("data", _input, &jf); + std::stringstream ss; + jf.flush(ss); + //bufferlist bl; + this->input_bl.append(ss.str()); + //set_input_bl(std::move(bl)); + } + +}; + template class RGWPostRESTResourceCR : public RGWSendRESTResourceCR { public: @@ -174,6 +202,18 @@ public: _params, _input, _result) {} }; +template +class RGWPutRawRESTResourceCR: public RGWSendRawRESTResourceCR { + public: + RGWPutRawRESTResourceCR(CephContext *_cct, RGWRESTConn *_conn, + RGWHTTPManager *_http_manager, + const string& _path, + rgw_http_param_pair *_params, bufferlist& _input, T *_result) + : RGWSendRawRESTResourceCR(_cct, _conn, _http_manager, "PUT", _path, _params, _input, _result){} + +}; + + template class RGWPutRESTResourceCR : public RGWSendRESTResourceCR { public: