From 0a93e74a0476e80c51ce5ec23b2a5ca1b28a3996 Mon Sep 17 00:00:00 2001 From: Seena Fallah Date: Fri, 28 Mar 2025 21:36:38 +0100 Subject: [PATCH] rgw: rest client callback when all headers are passed Signed-off-by: Seena Fallah --- src/rgw/driver/rados/rgw_lc_tier.cc | 6 ++---- src/rgw/driver/rados/rgw_sync_module_aws.cc | 6 ++---- src/rgw/rgw_rest_client.cc | 23 +++++++++++++++++---- src/rgw/rgw_rest_client.h | 3 +++ 4 files changed, 26 insertions(+), 12 deletions(-) diff --git a/src/rgw/driver/rados/rgw_lc_tier.cc b/src/rgw/driver/rados/rgw_lc_tier.cc index 58fb86b0af1f3..ece1e93370e80 100644 --- a/src/rgw/driver/rados/rgw_lc_tier.cc +++ b/src/rgw/driver/rados/rgw_lc_tier.cc @@ -822,10 +822,8 @@ void RGWLCCloudStreamPut::send_ready(const DoutPrefixProvider *dpp, const rgw_re } void RGWLCCloudStreamPut::handle_headers(const map& headers) { - for (const auto& h : headers) { - if (h.first == "ETAG") { - etag = h.second; - } + if (auto h = headers.find("ETAG"); h != headers.end()) { + etag = h->second; } } diff --git a/src/rgw/driver/rados/rgw_sync_module_aws.cc b/src/rgw/driver/rados/rgw_sync_module_aws.cc index 9d18bc9472bee..fa14d056f1682 100644 --- a/src/rgw/driver/rados/rgw_sync_module_aws.cc +++ b/src/rgw/driver/rados/rgw_sync_module_aws.cc @@ -987,10 +987,8 @@ public: } void handle_headers(const map& headers) { - for (auto h : headers) { - if (h.first == "ETAG") { - etag = h.second; - } + if (auto h = headers.find("ETAG"); h != headers.end()) { + etag = h->second; } } diff --git a/src/rgw/rgw_rest_client.cc b/src/rgw/rgw_rest_client.cc index a5f8cb61a3286..c3fdd1b687d39 100644 --- a/src/rgw/rgw_rest_client.cc +++ b/src/rgw/rgw_rest_client.cc @@ -47,7 +47,6 @@ int RGWHTTPSimpleRequest::receive_header(void *ptr, size_t len) unique_lock guard(out_headers_lock); char line[len + 1]; - char *s = (char *)ptr, *end = (char *)ptr + len; char *p = line; ldpp_dout(this, 30) << "receive_http_header" << dendl; @@ -58,22 +57,27 @@ int RGWHTTPSimpleRequest::receive_header(void *ptr, size_t len) continue; } if (*s == '\n') { + if (p == line) { + // End of headers (empty line "\r\n") + ldpp_dout(this, 30) << "All headers received" << dendl; + return handle_headers(out_headers, http_status); + } *p = '\0'; - ldpp_dout(this, 30) << "received header:" << line << dendl; + ldpp_dout(this, 30) << "received header: " << line << dendl; // TODO: fill whatever data required here char *l = line; char *tok = strsep(&l, " \t:"); if (tok && l) { while (*l == ' ') l++; - + if (strcmp(tok, "HTTP") == 0 || strncmp(tok, "HTTP/", 5) == 0) { http_status = atoi(l); if (http_status == 100) /* 100-continue response */ continue; status = rgw_http_error_to_errno(http_status); } else { - /* convert header field name to upper case */ + /* convert header field name to upper case */ char *src = tok; char buf[len + 1]; size_t i; @@ -93,10 +97,12 @@ int RGWHTTPSimpleRequest::receive_header(void *ptr, size_t len) return r; } } + p = line; } if (s != end) *p++ = *s++; } + return 0; } @@ -992,6 +998,15 @@ int RGWHTTPStreamRWRequest::complete_request(const DoutPrefixProvider* dpp, return status; } +int RGWHTTPStreamRWRequest::handle_headers(const map& headers, int http_status) +{ + if (cb) { + return cb->handle_headers(headers, http_status); + } + + return 0; +} + int RGWHTTPStreamRWRequest::handle_header(const string& name, const string& val) { if (name == "RGWX_EMBEDDED_METADATA_LEN") { diff --git a/src/rgw/rgw_rest_client.h b/src/rgw/rgw_rest_client.h index ffedcc17a94a3..16db7630a40ab 100644 --- a/src/rgw/rgw_rest_client.h +++ b/src/rgw/rgw_rest_client.h @@ -24,6 +24,7 @@ protected: bufferlist response; virtual int handle_header(const std::string& name, const std::string& val); + virtual int handle_headers(const std::map& headers, int http_status) { return 0; } void get_params_str(std::map& extra_args, std::string& dest); public: @@ -123,6 +124,7 @@ protected: bufferlist outbl; int handle_header(const std::string& name, const std::string& val) override; + int handle_headers(const std::map& headers, int http_status) override; public: int send_data(void *ptr, size_t len, bool *pause) override; int receive_data(void *ptr, size_t len, bool *pause) override; @@ -134,6 +136,7 @@ public: ReceiveCB() = default; virtual ~ReceiveCB() = default; virtual int handle_data(bufferlist& bl, bool *pause = nullptr) = 0; + virtual int handle_headers(const std::map& headers, int http_status) { return 0; } virtual void set_extra_data_len(uint64_t len) { extra_data_len = len; } -- 2.39.5