cmcfarlen commented on code in PR #12091:
URL: https://github.com/apache/trafficserver/pull/12091#discussion_r2007577278


##########
src/iocore/cache/CacheVC.cc:
##########
@@ -775,7 +775,9 @@ CacheVC::scanObject(int /* event ATS_UNUSED */, Event * /* 
e ATS_UNUSED */)
         goto Lskip;
       }
       if (!hostinfo_copied) {
-        memccpy(hname, vector.get(i)->request_get()->host_get(&hlen), 0, 500);
+        auto host{vector.get(i)->request_get()->host_get()};
+        hlen = static_cast<int>(host.length());
+        memccpy(hname, host.data(), 0, 500);

Review Comment:
   This is concerning here since string_view.data() isn't necessarily null 
terminated, but this copy is looking for one.  This should be memcpy or strncpy 
(but still add the termination).  Ideally hname would also be a string_view, 
but I'd have to dig further to see if that is possible without more refactoring.



##########
src/proxy/http/HttpSM.cc:
##########
@@ -4358,37 +4358,37 @@ HttpSM::check_sni_host()
   }
 
   int host_sni_policy = t_state.http_config_param->http_host_sni_policy;
-  if (snis->would_have_actions_for(std::string{host_name, 
static_cast<size_t>(host_len)}.c_str(), netvc->get_remote_endpoint(),
-                                   host_sni_policy) &&
+  if (snis->would_have_actions_for(std::string{host_name}.c_str(), 
netvc->get_remote_endpoint(), host_sni_policy) &&
       host_sni_policy > 0) {
     // In a SNI/Host mismatch where the Host would have triggered SNI policy, 
mark the transaction
     // to be considered for rejection after the remap phase passes.  Gives the 
opportunity to conf_remap
     // override the policy to be rejected in the end_remap logic
     const char *sni_value    = snis->get_sni_server_name();
     const char *action_value = host_sni_policy == 2 ? "terminate" : "continue";
     if (!sni_value || sni_value[0] == '\0') { // No SNI
-      Warning("No SNI for TLS request with hostname %.*s action=%s", host_len, 
host_name, action_value);
-      SMDbg(dbg_ctl_ssl_sni, "No SNI for TLS request with hostname %.*s 
action=%s", host_len, host_name, action_value);
+      Warning("No SNI for TLS request with hostname %.*s action=%s", host_len, 
host_name.data(), action_value);
+      SMDbg(dbg_ctl_ssl_sni, "No SNI for TLS request with hostname %.*s 
action=%s", host_len, host_name.data(), action_value);
       if (host_sni_policy == 2) {
         swoc::bwprint(error_bw_buffer, "No SNI for TLS request: connecting to 
{} for host='{}', returning a 403",
-                      t_state.client_info.dst_addr, 
std::string_view{host_name, static_cast<size_t>(host_len)});
+                      t_state.client_info.dst_addr, host_name.data());

Review Comment:
   You should drop `.data()` for these `fmt` style prints.  They support sv 
directly.



##########
src/proxy/http/HttpSM.cc:
##########
@@ -5193,9 +5193,8 @@ HttpSM::get_outbound_sni() const
 
   if (policy.empty() || policy == "host"_tv) {
     // By default the host header field value is used for the SNI.
-    int         len;
-    char const *ptr = t_state.hdr_info.server_request.host_get(&len);
-    zret.assign(ptr, len);
+    auto host{t_state.hdr_info.server_request.host_get()};
+    zret.assign(host.data(), static_cast<int>(host.length()));

Review Comment:
   I think this could be: `zret = t_state.hdr_info.server_request.host_get()`



##########
src/proxy/http/HttpTransact.cc:
##########
@@ -591,10 +591,9 @@ is_negative_caching_appropriate(HttpTransact::State *s)
 inline static ResolveInfo::UpstreamResolveStyle
 find_server_and_update_current_info(HttpTransact::State *s)
 {
-  int         host_len;
-  const char *host = s->hdr_info.client_request.host_get(&host_len);
+  auto host{s->hdr_info.client_request.host_get()};
 
-  if (is_localhost(host, host_len)) {
+  if (is_localhost(host.data(), static_cast<int>(host.length()))) {

Review Comment:
   `is_localhost` could take a string_view instead.  This is the only place it 
is called.



-- 
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