1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
4 #ifndef CEPH_RGW_REST_CLIENT_H
5 #define CEPH_RGW_REST_CLIENT_H
7 #include "rgw_http_client.h"
11 class RGWRESTSimpleRequest
: public RGWHTTPClient
{
18 map
<string
, string
> out_headers
;
21 bufferlist::iterator
*send_iter
;
23 size_t max_response
; /* we need this as we don't stream out response */
26 virtual int handle_header(const string
& name
, const string
& val
);
27 void append_param(string
& dest
, const string
& name
, const string
& val
);
28 void get_params_str(map
<string
, string
>& extra_args
, string
& dest
);
30 int sign_request(RGWAccessKey
& key
, RGWEnv
& env
, req_info
& info
);
32 RGWRESTSimpleRequest(CephContext
*_cct
, const string
& _url
, param_vec_t
*_headers
,
33 param_vec_t
*_params
) : RGWHTTPClient(_cct
), http_status(0), status(0),
34 url(_url
), send_iter(NULL
),
36 set_headers(_headers
);
40 void set_headers(param_vec_t
*_headers
) {
45 void set_params(param_vec_t
*_params
) {
50 int receive_header(void *ptr
, size_t len
) override
;
51 int receive_data(void *ptr
, size_t len
) override
;
52 int send_data(void *ptr
, size_t len
) override
;
54 bufferlist
& get_response() { return response
; }
56 int execute(RGWAccessKey
& key
, const char *method
, const char *resource
);
57 int forward_request(RGWAccessKey
& key
, req_info
& info
, size_t max_response
, bufferlist
*inbl
, bufferlist
*outbl
);
59 map
<string
, string
>& get_out_headers() { return out_headers
; }
61 int get_http_status() { return http_status
; }
66 class RGWRESTStreamWriteRequest
: public RGWRESTSimpleRequest
{
68 list
<bufferlist
> pending_send
;
70 RGWHTTPManager http_manager
;
72 int add_output_data(bufferlist
& bl
);
73 int send_data(void *ptr
, size_t len
) override
;
75 RGWRESTStreamWriteRequest(CephContext
*_cct
, const string
& _url
, param_vec_t
*_headers
,
76 param_vec_t
*_params
) : RGWRESTSimpleRequest(_cct
, _url
, _headers
, _params
),
77 lock("RGWRESTStreamWriteRequest"), cb(NULL
), http_manager(_cct
) {}
78 ~RGWRESTStreamWriteRequest() override
;
79 int put_obj_init(RGWAccessKey
& key
, rgw_obj
& obj
, uint64_t obj_size
, map
<string
, bufferlist
>& attrs
);
80 int complete(string
& etag
, real_time
*mtime
);
82 RGWGetDataCB
*get_out_cb() { return cb
; }
85 class RGWRESTStreamRWRequest
: public RGWRESTSimpleRequest
{
92 RGWHTTPManager http_manager
;
96 int handle_header(const string
& name
, const string
& val
) override
;
98 int send_data(void *ptr
, size_t len
) override
;
99 int receive_data(void *ptr
, size_t len
) override
;
101 RGWRESTStreamRWRequest(CephContext
*_cct
, const char *_method
, const string
& _url
, RGWGetDataCB
*_cb
,
102 param_vec_t
*_headers
, param_vec_t
*_params
) : RGWRESTSimpleRequest(_cct
, _url
, _headers
, _params
),
103 lock("RGWRESTStreamReadRequest"), cb(_cb
),
104 chunk_ofs(0), ofs(0), http_manager(_cct
), method(_method
), write_ofs(0) {
106 virtual ~RGWRESTStreamRWRequest() override
{}
107 int send_request(RGWAccessKey
& key
, map
<string
, string
>& extra_headers
, rgw_obj
& obj
, RGWHTTPManager
*mgr
= NULL
);
108 int send_request(RGWAccessKey
*key
, map
<string
, string
>& extra_headers
, const string
& resource
, bufferlist
*send_data
= NULL
/* optional input data */, RGWHTTPManager
*mgr
= NULL
);
109 int complete_request(string
& etag
, real_time
*mtime
, uint64_t *psize
, map
<string
, string
>& attrs
);
111 void set_outbl(bufferlist
& _outbl
) {
115 void set_in_cb(RGWGetDataCB
*_cb
) { cb
= _cb
; }
118 class RGWRESTStreamReadRequest
: public RGWRESTStreamRWRequest
{
120 RGWRESTStreamReadRequest(CephContext
*_cct
, const string
& _url
, RGWGetDataCB
*_cb
, param_vec_t
*_headers
,
121 param_vec_t
*_params
) : RGWRESTStreamRWRequest(_cct
, "GET", _url
, _cb
, _headers
, _params
) {}
124 class RGWRESTStreamHeadRequest
: public RGWRESTStreamRWRequest
{
126 RGWRESTStreamHeadRequest(CephContext
*_cct
, const string
& _url
, RGWGetDataCB
*_cb
, param_vec_t
*_headers
,
127 param_vec_t
*_params
) : RGWRESTStreamRWRequest(_cct
, "HEAD", _url
, _cb
, _headers
, _params
) {}