return 0;
}
-int RGWPostHTTPData::send_data(void* ptr, size_t len)
+int RGWHTTPTransceiver::send_data(void* ptr, size_t len)
{
int length_to_copy = 0;
if (post_data_index < post_data.length()) {
return length_to_copy;
}
-int RGWPostHTTPData::receive_header(void *ptr, size_t len) {
- char line[len + 1];
-
- char *s = (char *)ptr, *end = (char *)ptr + len;
- char *p = line;
- ldout(cct, 20) << "RGWPostHTTPData::receive_header parsing HTTP headers" << dendl;
-
- while (s != end) {
- if (*s == '\r') {
- s++;
- continue;
- }
- if (*s == '\n') {
- *p = '\0';
- ldout(cct, 20) << "RGWPostHTTPData::receive_header: line="
- << line << dendl;
- // TODO: fill whatever data required here
- char *l = line;
- char *tok = strsep(&l, " \t:");
- if (tok) {
- while (l && *l == ' ') {
- l++;
- }
-
- if (strcasecmp(tok, "X-Subject-Token") == 0) {
- subject_token = l;
- }
- }
- }
- if (s != end) {
- *p++ = *s++;
- }
- }
- return 0;
-}
#if HAVE_CURL_MULTI_WAIT
static const long HTTP_STATUS_UNAUTHORIZED = 401;
virtual ~RGWHTTPClient();
- explicit RGWHTTPClient(CephContext *_cct)
+ explicit RGWHTTPClient(CephContext *cct)
: send_len(0),
has_send_len(false),
http_status(HTTP_STATUS_NOSTATUS),
req_data(nullptr),
user_info(nullptr),
verify_ssl(true),
- cct(_cct) {
+ cct(cct) {
}
void set_user_info(void *info) {
};
-class RGWPostHTTPData : public RGWHTTPClient {
- bufferlist *bl;
+class RGWHTTPTransceiver : public RGWHTTPHeadersCollector {
+ bufferlist * const read_bl;
std::string post_data;
size_t post_data_index;
- std::string subject_token;
+
public:
- RGWPostHTTPData(CephContext *_cct, bufferlist *_bl) : RGWHTTPClient(_cct), bl(_bl), post_data_index(0) {}
- RGWPostHTTPData(CephContext *_cct, bufferlist *_bl, bool verify_ssl) : RGWHTTPClient(_cct), bl(_bl), post_data_index(0){
+ RGWHTTPTransceiver(CephContext * const cct,
+ bufferlist * const read_bl,
+ const header_spec_t intercept_headers = {})
+ : RGWHTTPHeadersCollector(cct, intercept_headers),
+ read_bl(read_bl),
+ post_data_index(0) {
+ }
+
+ RGWHTTPTransceiver(CephContext * const cct,
+ bufferlist * const read_bl,
+ const bool verify_ssl,
+ const header_spec_t intercept_headers = {})
+ : RGWHTTPHeadersCollector(cct, intercept_headers),
+ read_bl(read_bl),
+ post_data_index(0) {
set_verify_ssl(verify_ssl);
}
this->post_data = _post_data;
}
- std::string get_subject_token() {
- return subject_token;
- }
-
protected:
- int send_data(void* ptr, size_t len);
+ int send_data(void* ptr, size_t len) override;
- int receive_data(void *ptr, size_t len) {
- bl->append((char *)ptr, len);
+ int receive_data(void *ptr, size_t len) override {
+ read_bl->append((char *)ptr, len);
return 0;
}
-
- int receive_header(void *ptr, size_t len);
};
+typedef RGWHTTPTransceiver RGWPostHTTPData;
+
class RGWCompletionManager;
}
-typedef RGWPostHTTPData RGWValidateKeystoneToken;
-typedef RGWPostHTTPData RGWGetKeystoneAdminToken;
-typedef RGWPostHTTPData RGWGetRevokedTokens;
+class RGWKeystoneHTTPTransceiver : public RGWHTTPTransceiver {
+public:
+ RGWKeystoneHTTPTransceiver(CephContext * const cct,
+ bufferlist * const token_body_bl)
+ : RGWHTTPTransceiver(cct, token_body_bl,
+ cct->_conf->rgw_keystone_verify_ssl,
+ { "X-Subject-Token" }) {
+ }
+
+ std::string get_subject_token() const {
+ try {
+ return get_header_value("X-Subject-Token");
+ } catch (std::out_of_range&) {
+ return header_value_t();
+ }
+ }
+};
+
+typedef RGWKeystoneHTTPTransceiver RGWValidateKeystoneToken;
+typedef RGWKeystoneHTTPTransceiver RGWGetKeystoneAdminToken;
+typedef RGWKeystoneHTTPTransceiver RGWGetRevokedTokens;
static RGWKeystoneTokenCache *keystone_token_cache = NULL;
int RGWSwift::get_keystone_url(CephContext * const cct,
std::string& url)
{
+ // FIXME: it seems we don't need RGWGetRevokedToken here
bufferlist bl;
- RGWGetRevokedTokens req(cct, &bl, cct->_conf->rgw_keystone_verify_ssl);
+ RGWGetRevokedTokens req(cct, &bl);
url = cct->_conf->rgw_keystone_url;
if (url.empty()) {
}
bufferlist token_bl;
- RGWGetKeystoneAdminToken token_req(cct, &token_bl, cct->_conf->rgw_keystone_verify_ssl);
+ RGWGetKeystoneAdminToken token_req(cct, &token_bl);
token_req.append_header("Content-Type", "application/json");
JSONFormatter jf;
/* can't decode, just go to the keystone server for validation */
- RGWValidateKeystoneToken validate(cct, &bl, cct->_conf->rgw_keystone_verify_ssl);
+ RGWValidateKeystoneToken validate(cct, &bl);
string url = g_conf->rgw_keystone_url;
if (url.empty()) {