trafficserver-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From n..@apache.org
Subject [3/3] git commit: TS-1364
Date Thu, 06 Sep 2012 10:57:49 GMT
TS-1364

Fix up reverse-proxying URL headers in all cases,
not just a regular redirection target.


Project: http://git-wip-us.apache.org/repos/asf/trafficserver/repo
Commit: http://git-wip-us.apache.org/repos/asf/trafficserver/commit/b18d8424
Tree: http://git-wip-us.apache.org/repos/asf/trafficserver/tree/b18d8424
Diff: http://git-wip-us.apache.org/repos/asf/trafficserver/diff/b18d8424

Branch: refs/heads/master
Commit: b18d8424a605ef7170c6d4db5fcb8ee932d0b5d2
Parents: 1798bb9
Author: niq <niq@apache.org>
Authored: Thu Sep 6 11:47:30 2012 +0100
Committer: niq <niq@apache.org>
Committed: Thu Sep 6 11:47:30 2012 +0100

----------------------------------------------------------------------
 proxy/http/HttpTransact.cc     |    6 +---
 proxy/http/remap/UrlRewrite.cc |   45 ++++++++++++++++++++++------------
 2 files changed, 31 insertions(+), 20 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/trafficserver/blob/b18d8424/proxy/http/HttpTransact.cc
----------------------------------------------------------------------
diff --git a/proxy/http/HttpTransact.cc b/proxy/http/HttpTransact.cc
index 2313b73..030cf3f 100644
--- a/proxy/http/HttpTransact.cc
+++ b/proxy/http/HttpTransact.cc
@@ -7960,10 +7960,8 @@ HttpTransact::build_response(State* s, HTTPHdr* base_response, HTTPHdr*
outgoing
   HttpTransactHeaders::convert_response(outgoing_version, outgoing_response);
 
   // process reverse mappings on the location header
-  HTTPStatus outgoing_status = outgoing_response->status_get();
-
-  if ((outgoing_status != 200) && (((outgoing_status >= 300) && (outgoing_status
< 400)) || (outgoing_status == 201)))
-    response_url_remap(outgoing_response);
+  // TS-1364: do this regardless of response code
+  response_url_remap(outgoing_response);
 
   if (s->http_config_param->enable_http_stats) {
     if (s->hdr_info.server_response.valid() && s->http_config_param->wuts_enabled)
{

http://git-wip-us.apache.org/repos/asf/trafficserver/blob/b18d8424/proxy/http/remap/UrlRewrite.cc
----------------------------------------------------------------------
diff --git a/proxy/http/remap/UrlRewrite.cc b/proxy/http/remap/UrlRewrite.cc
index a739695..a87cfb6 100644
--- a/proxy/http/remap/UrlRewrite.cc
+++ b/proxy/http/remap/UrlRewrite.cc
@@ -790,6 +790,7 @@ UrlRewrite::_doRemap(UrlMappingContainer &mapping_container, URL *request_url)
 
 
 /** Used to do the backwards lookups. */
+#define N_URL_HEADERS 4
 bool
 UrlRewrite::ReverseMap(HTTPHdr *response_header)
 {
@@ -801,34 +802,46 @@ UrlRewrite::ReverseMap(HTTPHdr *response_header)
   int host_len;
   char *new_loc_hdr;
   int new_loc_length;
+  int i;
+  const struct {
+    const char *const field;
+    const int len;
+  } url_headers[N_URL_HEADERS] = {
+    { MIME_FIELD_LOCATION, MIME_LEN_LOCATION } ,
+    { MIME_FIELD_CONTENT_LOCATION, MIME_LEN_CONTENT_LOCATION } ,
+    { "URI", 3 } ,
+    { "Destination", 11 }
+  };
 
   if (unlikely(num_rules_reverse == 0)) {
     ink_assert(reverse_mappings.empty());
     return false;
   }
 
-  location_hdr = response_header->value_get(MIME_FIELD_LOCATION, MIME_LEN_LOCATION, &loc_length);
+  for (i = 0; i < N_URL_HEADERS; ++i) {
+    location_hdr = response_header->value_get(url_headers[i].field, url_headers[i].len,
&loc_length);
 
-  if (location_hdr == NULL) {
-    Debug("url_rewrite", "Reverse Remap called with empty location header");
-    return false;
-  }
+    if (location_hdr == NULL) {
+      continue;
+    }
 
-  location_url.create(NULL);
-  location_url.parse(location_hdr, loc_length);
+    location_url.create(NULL);
+    location_url.parse(location_hdr, loc_length);
 
-  host = location_url.host_get(&host_len);
+    host = location_url.host_get(&host_len);
 
-  UrlMappingContainer reverse_mapping(response_header->m_heap);
+    UrlMappingContainer reverse_mapping(response_header->m_heap);
 
-  if (reverseMappingLookup(&location_url, location_url.port_get(), host, host_len, reverse_mapping))
{
-    remap_found = true;
-    _doRemap(reverse_mapping, &location_url);
-    new_loc_hdr = location_url.string_get_ref(&new_loc_length);
-    response_header->value_set(MIME_FIELD_LOCATION, MIME_LEN_LOCATION, new_loc_hdr, new_loc_length);
-  }
+    if (reverseMappingLookup(&location_url, location_url.port_get(), host, host_len,
reverse_mapping)) {
+      if (i == 0)
+        remap_found = true;
+      _doRemap(reverse_mapping, &location_url);
+      new_loc_hdr = location_url.string_get_ref(&new_loc_length);
+      response_header->value_set(url_headers[i].field, url_headers[i].len, new_loc_hdr,
new_loc_length);
+    }
 
-  location_url.destroy();
+    location_url.destroy();
+  }
   return remap_found;
 }
 


Mime
View raw message