You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@trafficserver.apache.org by bc...@apache.org on 2014/07/14 21:27:44 UTC

git commit: TS-1475: fix clang warning

Repository: trafficserver
Updated Branches:
  refs/heads/master b82a38eee -> b1f511ca4


TS-1475: fix clang warning


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

Branch: refs/heads/master
Commit: b1f511ca488a642652207625c72843b5b823856a
Parents: b82a38e
Author: Bryan Call <bc...@apache.org>
Authored: Mon Jul 14 13:27:30 2014 -0600
Committer: Bryan Call <bc...@apache.org>
Committed: Mon Jul 14 13:27:30 2014 -0600

----------------------------------------------------------------------
 proxy/http/HttpTransact.cc | 58 +++++++++++++++++++++++------------------
 1 file changed, 33 insertions(+), 25 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/trafficserver/blob/b1f511ca/proxy/http/HttpTransact.cc
----------------------------------------------------------------------
diff --git a/proxy/http/HttpTransact.cc b/proxy/http/HttpTransact.cc
index dc41873..2192a9a 100644
--- a/proxy/http/HttpTransact.cc
+++ b/proxy/http/HttpTransact.cc
@@ -1107,28 +1107,40 @@ HttpTransact::handle_websocket_connection(State *s) {
 }
 
 
+static bool mimefield_value_equal(MIMEField *field, const char *value, const int value_len)
+{
+  if (field != NULL) {
+    int field_value_len = 0;
+    const char *field_value = field->value_get(&field_value_len);
+    if (field_value != NULL) {
+      if (field_value_len == value_len) {
+        return !strncasecmp(field_value, value, value_len);
+      }
+    }
+  }
+  return false;
+}
+
 void
 HttpTransact::ModifyRequest(State* s)
 {
   int scheme, hostname_len;
   const char *hostname;
-  MIMEField *max_forwards_f;
-  int max_forwards = -1;
-  HTTPHdr* request = &s->hdr_info.client_request;
+  HTTPHdr& request = s->hdr_info.client_request;
 
   DebugTxn("http_trans", "START HttpTransact::ModifyRequest");
 
-  // Intialize the state vars necessary to sending error responses
-  bootstrap_state_variables_from_request(s, request);
+  // Initialize the state vars necessary to sending error responses
+  bootstrap_state_variables_from_request(s, &request);
 
   ////////////////////////////////////////////////
   // If there is no scheme default to http      //
   ////////////////////////////////////////////////
-  URL *url = request->url_get();
+  URL *url = request.url_get();
 
   s->orig_scheme = (scheme = url->scheme_get_wksidx());
 
-  s->method = s->hdr_info.client_request.method_get_wksidx();
+  s->method = request.method_get_wksidx();
   if (scheme < 0 && s->method != HTTP_WKSIDX_CONNECT) {
     if (s->client_info.port_attribute == HttpProxyPort::TRANSPORT_SSL) {
       url->scheme_set(URL_SCHEME_HTTPS, URL_LEN_HTTPS);
@@ -1139,7 +1151,7 @@ HttpTransact::ModifyRequest(State* s)
     }
   }
 
-  if (s->method == HTTP_WKSIDX_CONNECT && !request->is_port_in_header())
+  if (s->method == HTTP_WKSIDX_CONNECT && !request.is_port_in_header())
     url->port_set(80);
 
   // Ugly - this must come after the call to url->scheme_set or
@@ -1147,24 +1159,23 @@ HttpTransact::ModifyRequest(State* s)
   // The solution should be to move the scheme detecting logic in to
   // the header class, rather than doing it in a random bit of
   // external code.
-  hostname = request->host_get(&hostname_len);
-  if (!request->is_target_in_url())
+  hostname = request.host_get(&hostname_len);
+  if (!request.is_target_in_url()) {
     s->hdr_info.client_req_is_server_style = true;
+  }
 
   // If the incoming request is proxy-style make sure the Host: header
   // matches the incoming request URL. The exception is if we have
-  // Max-Fowards set to 0 in the request (ToDo: why??)
-  max_forwards_f = s->hdr_info.client_request.field_find(MIME_FIELD_MAX_FORWARDS, MIME_LEN_MAX_FORWARDS);
-  if (max_forwards_f) {
-    max_forwards = max_forwards_f->value_get_int();
+  // Max-Forwards set to 0 in the request
+  int max_forwards = -1;  // -1 is a valid value meaning that it didn't find the header
+  if (request.presence(MIME_PRESENCE_MAX_FORWARDS)) {
+    max_forwards = request.get_max_forwards();
   }
 
   if ((max_forwards != 0) && !s->hdr_info.client_req_is_server_style && s->method != HTTP_WKSIDX_CONNECT) {
-    MIMEField *host_field = s->hdr_info.client_request.field_find(MIME_FIELD_HOST, MIME_LEN_HOST);
+    MIMEField *host_field = request.field_find(MIME_FIELD_HOST, MIME_LEN_HOST);
     int host_val_len = hostname_len;
     const char **host_val = &hostname;
-    int req_host_val_len;
-    const char *req_host_val;
     int port = url->port_get_raw();
     char *buf = NULL;
 
@@ -1176,17 +1187,14 @@ HttpTransact::ModifyRequest(State* s)
       host_val = (const char**)(&buf);
     }
 
-    if (!host_field ||
-        ((req_host_val = host_field->value_get(&req_host_val_len)) == NULL) ||
-        (host_val_len != req_host_val_len) ||
-        (strncasecmp(*host_val, req_host_val, host_val_len) != 0)) {
+    if (mimefield_value_equal(host_field, *host_val, host_val_len)) {
 
       if (!host_field) { // Assure we have a Host field, before setting it
-        host_field = s->hdr_info.client_request.field_create(MIME_FIELD_HOST, MIME_LEN_HOST);
-        s->hdr_info.client_request.field_attach(host_field);
+        host_field = request.field_create(MIME_FIELD_HOST, MIME_LEN_HOST);
+        request.field_attach(host_field);
       }
-      s->hdr_info.client_request.field_value_set(host_field, *host_val, host_val_len);
-      request->mark_target_dirty();
+      request.field_value_set(host_field, *host_val, host_val_len);
+      request.mark_target_dirty();
     }
   }