masaori335 commented on code in PR #13697:
URL: https://github.com/apache/trafficserver/pull/13697#discussion_r4022191367


##########
plugins/stats_over_http/stats_over_http.cc:
##########
@@ -1151,21 +1152,26 @@ stats_origin(TSCont contp, TSEvent /* event ATS_UNUSED 
*/, void *edata)
     my_state->output_format = output_format_t::JSON_OUTPUT; // default to json 
output
     // accept header exists, use it to determine response type
     if (accept_field != TS_NULL_MLOC) {
-      int         len = -1;
-      const char *str = TSMimeHdrFieldValueStringGet(reqp, hdr_loc, 
accept_field, -1, &len);
+      int              len = -1;
+      const char      *str = TSMimeHdrFieldValueStringGet(reqp, hdr_loc, 
accept_field, -1, &len);
+      std::string_view accept{};
+
+      if (str != nullptr && len > 0) {
+        accept = std::string_view{str, 
static_cast<std::string_view::size_type>(len)};
+      }
 
       // Parse the Accept header, default to JSON output unless its another 
supported format
-      if (!strncasecmp(str, "text/csv", len)) {
+      if (ts::iequals(accept, "text/csv")) {
         Dbg(dbg_ctl, "Saw text/csv in accept header, sending CSV output.");
         my_state->output_format = output_format_t::CSV_OUTPUT;
-      } else if (!strncasecmp(str, "text/plain; version=0.0.4", len)) {
+      } else if (ts::iequals(accept, "text/plain; version=0.0.4")) {
         Dbg(dbg_ctl, "Saw text/plain; version=0.0.4 in accept header, sending 
Prometheus output.");
         my_state->output_format = output_format_t::PROMETHEUS_OUTPUT;
-      } else if (!strncasecmp(str, "text/plain; version=2.0.0", len)) {
+      } else if (ts::iequals(accept, "text/plain; version=2.0.0")) {
         Dbg(dbg_ctl, "Saw text/plain; version=2.0.0 in accept header, sending 
Prometheus v2 output.");
         my_state->output_format = output_format_t::PROMETHEUS_V2_OUTPUT;
       } else {
-        Dbg(dbg_ctl, "Saw %.*s in accept header, defaulting to JSON output.", 
len, str);
+        Dbg(dbg_ctl, "Saw %.*s in accept header, defaulting to JSON output.", 
static_cast<int>(accept.size()), accept.data());

Review Comment:
   Makes sense. Fixed by 
[6134b02](https://github.com/apache/trafficserver/pull/13697/commits/6134b029a3b07ef5d62bef451cf95aa2a7618118)



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to