]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
rgw: use string_view to parse Accept header
authorCasey Bodley <cbodley@redhat.com>
Tue, 16 May 2023 12:24:29 +0000 (08:24 -0400)
committerCasey Bodley <cbodley@redhat.com>
Tue, 16 May 2023 12:27:29 +0000 (08:27 -0400)
avoid copying the header into a separate buffer to do comparisons

Fixes: https://tracker.ceph.com/issues/59490
Signed-off-by: Casey Bodley <cbodley@redhat.com>
src/rgw/rgw_rest.cc

index a8b8e0dff99b61b3ebac4b677fe041687a0be51c..5bba3fce4d1cef819275634a695bb91812077125 100644 (file)
@@ -1727,17 +1727,15 @@ int RGWHandler_REST::allocate_formatter(req_state *s,
     } else {
       const char *accept = s->info.env->get("HTTP_ACCEPT");
       if (accept) {
-        char format_buf[64];
-        unsigned int i = 0;
-        for (; i < sizeof(format_buf) - 1 && accept[i] && accept[i] != ';'; ++i) {
-          format_buf[i] = accept[i];
-        }
-        format_buf[i] = 0;
-        if ((strcmp(format_buf, "text/xml") == 0) || (strcmp(format_buf, "application/xml") == 0)) {
+        // trim at first ;
+        std::string_view format = accept;
+        format = format.substr(0, format.find(';'));
+
+        if (format == "text/xml" || format == "application/xml") {
           type = RGWFormat::XML;
-        } else if (strcmp(format_buf, "application/json") == 0) {
+        } else if (format == "application/json") {
           type = RGWFormat::JSON;
-        } else if (strcmp(format_buf, "text/html") == 0) {
+        } else if (format == "text/html") {
           type = RGWFormat::HTML;
         }
       }