]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
rgw: rest client callback when all headers are passed
authorSeena Fallah <seenafallah@gmail.com>
Fri, 28 Mar 2025 20:36:38 +0000 (21:36 +0100)
committerSeena Fallah <seenafallah@gmail.com>
Mon, 28 Apr 2025 16:56:06 +0000 (18:56 +0200)
Signed-off-by: Seena Fallah <seenafallah@gmail.com>
src/rgw/driver/rados/rgw_lc_tier.cc
src/rgw/driver/rados/rgw_sync_module_aws.cc
src/rgw/rgw_rest_client.cc
src/rgw/rgw_rest_client.h

index 58fb86b0af1f3a7612475e5759dd47ef1bd7a548..ece1e93370e801016a8fc0e2cc706c94f30ea19e 100644 (file)
@@ -822,10 +822,8 @@ void RGWLCCloudStreamPut::send_ready(const DoutPrefixProvider *dpp, const rgw_re
 }
 
 void RGWLCCloudStreamPut::handle_headers(const map<string, string>& 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;
   }
 }
 
index 9d18bc9472bee865e0910f2de9692afb78c2aed1..fa14d056f16821e67839739af73769d0b4d70e1e 100644 (file)
@@ -987,10 +987,8 @@ public:
   }
 
   void handle_headers(const map<string, string>& headers) {
-    for (auto h : headers) {
-      if (h.first == "ETAG") {
-        etag = h.second;
-      }
+    if (auto h = headers.find("ETAG"); h != headers.end()) {
+      etag = h->second;
     }
   }
 
index a5f8cb61a3286f5538b98e6227ac719cfe5204ed..c3fdd1b687d399e9944545af31b42ead89fccd38 100644 (file)
@@ -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<string, string>& 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") {
index ffedcc17a94a39db0607274669a651e17d0db9be..16db7630a40ab1eb8bc52d086e0a8e3764b19e8d 100644 (file)
@@ -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<std::string, std::string>& headers, int http_status) { return 0; }
   void get_params_str(std::map<std::string, std::string>& 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<std::string, std::string>& 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<std::string, std::string>& headers, int http_status) { return 0; }
       virtual void set_extra_data_len(uint64_t len) {
         extra_data_len = len;
       }