This is an automated email from the ASF dual-hosted git repository.

eze pushed a commit to branch 9.2.x
in repository https://gitbox.apache.org/repos/asf/trafficserver.git


The following commit(s) were added to refs/heads/9.2.x by this push:
     new aaa2856cd1 Fix ordering Via response header values (#9239) (#12087)
aaa2856cd1 is described below

commit aaa2856cd1bcabcd83e261aaa740f5dd24689346
Author: Hiroaki Nakamura <[email protected]>
AuthorDate: Tue Mar 18 07:13:35 2025 +0900

    Fix ordering Via response header values (#9239) (#12087)
    
    When we craft the Via header, the origin's Via should come before our Via 
headers. Before this patch, the order was reversed. This fixes that.
---
 proxy/http/HttpTransact.cc        | 9 +++++++++
 proxy/http/HttpTransact.h         | 2 ++
 proxy/http/HttpTransactHeaders.cc | 2 +-
 3 files changed, 12 insertions(+), 1 deletion(-)

diff --git a/proxy/http/HttpTransact.cc b/proxy/http/HttpTransact.cc
index 31810e45d1..088e14d537 100644
--- a/proxy/http/HttpTransact.cc
+++ b/proxy/http/HttpTransact.cc
@@ -4706,11 +4706,17 @@ 
HttpTransact::handle_cache_operation_on_forward_server_response(State *s)
     //  the order of the fields
     MIMEField *resp_via = 
s->hdr_info.server_response.field_find(MIME_FIELD_VIA, MIME_LEN_VIA);
     if (resp_via) {
+      int saved_via_len = 0;
+      ts::LocalBufferWriter<HTTP_OUR_VIA_MAX_LENGTH> saved_via_w;
       MIMEField *our_via;
       our_via = s->hdr_info.client_response.field_find(MIME_FIELD_VIA, 
MIME_LEN_VIA);
       if (our_via == nullptr) {
         our_via = s->hdr_info.client_response.field_create(MIME_FIELD_VIA, 
MIME_LEN_VIA);
         s->hdr_info.client_response.field_attach(our_via);
+      } else {
+        const char *src = our_via->value_get(&saved_via_len);
+        saved_via_w.write(src, saved_via_len);
+        s->hdr_info.client_response.field_value_set(our_via, "", 0, true);
       }
       // HDR FIX ME - Multiple appends are VERY slow
       while (resp_via) {
@@ -4719,6 +4725,9 @@ 
HttpTransact::handle_cache_operation_on_forward_server_response(State *s)
         s->hdr_info.client_response.field_value_append(our_via, cfield, clen, 
true);
         resp_via = resp_via->m_next_dup;
       }
+      if (saved_via_w.size()) {
+        s->hdr_info.client_response.field_value_append(our_via, 
saved_via_w.data(), saved_via_w.size(), true);
+      }
     }
     // a warning text is added only in the case of a NOT MODIFIED response
     if (warn_text) {
diff --git a/proxy/http/HttpTransact.h b/proxy/http/HttpTransact.h
index 64e2cc58cd..f3766c26ee 100644
--- a/proxy/http/HttpTransact.h
+++ b/proxy/http/HttpTransact.h
@@ -44,6 +44,8 @@
 #include "ProxySession.h"
 #include "MgmtDefs.h"
 
+#define HTTP_OUR_VIA_MAX_LENGTH 1024 // 512-bytes for hostname+via string, 
512-bytes for the debug info
+
 #define HTTP_RELEASE_ASSERT(X) ink_release_assert(X)
 
 #define DUMP_HEADER(T, H, I, S)                                 \
diff --git a/proxy/http/HttpTransactHeaders.cc 
b/proxy/http/HttpTransactHeaders.cc
index 90b97951da..5f0d1dabf6 100644
--- a/proxy/http/HttpTransactHeaders.cc
+++ b/proxy/http/HttpTransactHeaders.cc
@@ -837,7 +837,7 @@ 
HttpTransactHeaders::insert_hsts_header_in_response(HttpTransact::State *s, HTTP
 void
 HttpTransactHeaders::insert_via_header_in_response(HttpTransact::State *s, 
HTTPHdr *header)
 {
-  char new_via_string[1024]; // 512-bytes for hostname+via string, 512-bytes 
for the debug info
+  char new_via_string[HTTP_OUR_VIA_MAX_LENGTH];
   char *via_string = new_via_string;
   char *via_limit  = via_string + sizeof(new_via_string);
 

Reply via email to