trafficserver-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jpe...@apache.org
Subject [trafficserver] 02/02: Improve readability in HttpTransact::build_response.
Date Sat, 05 Nov 2016 23:40:01 GMT
This is an automated email from the ASF dual-hosted git repository.

jpeach pushed a commit to branch master
in repository https://git-dual.apache.org/repos/asf/trafficserver.git

commit 5589c84fba4b8df5346c6c6e49bdd41db3ed9d05
Author: James Peach <jpeach@apache.org>
AuthorDate: Sat Nov 5 16:33:07 2016 -0700

    Improve readability in HttpTransact::build_response.
---
 proxy/http/HttpTransact.cc | 34 ++++++++++++++++++++--------------
 1 file changed, 20 insertions(+), 14 deletions(-)

diff --git a/proxy/http/HttpTransact.cc b/proxy/http/HttpTransact.cc
index 8e378c4..54c8335 100644
--- a/proxy/http/HttpTransact.cc
+++ b/proxy/http/HttpTransact.cc
@@ -7939,22 +7939,28 @@ HttpTransact::build_response(State *s, HTTPHdr *base_response, HTTPHdr
*outgoing
         // Since a proxy doesn't know if a header differs from
         // a user agent's cached document or not, all are sent.
         {
-          static const char *field_name[] = {MIME_FIELD_ETAG, MIME_FIELD_CONTENT_LOCATION,
MIME_FIELD_EXPIRES,
-                                             MIME_FIELD_CACHE_CONTROL, MIME_FIELD_VARY};
-          static int field_len[] = {MIME_LEN_ETAG, MIME_LEN_CONTENT_LOCATION, MIME_LEN_EXPIRES,
MIME_LEN_CACHE_CONTROL,
-                                    MIME_LEN_VARY};
-          static uint64_t field_presence[] = {MIME_PRESENCE_ETAG, MIME_PRESENCE_CONTENT_LOCATION,
MIME_PRESENCE_EXPIRES,
-                                              MIME_PRESENCE_CACHE_CONTROL, MIME_PRESENCE_VARY};
-          MIMEField *field;
-          int len;
-          const char *value;
-
-          for (size_t i = 0; i < sizeof(field_len) / sizeof(field_len[0]); i++) {
-            if (base_response->presence(field_presence[i])) {
-              field = base_response->field_find(field_name[i], field_len[i]);
+          static const struct {
+            const char *name;
+            int len;
+            uint64_t presence;
+          } fields[] = {
+            {MIME_FIELD_ETAG, MIME_LEN_ETAG, MIME_PRESENCE_ETAG},
+            {MIME_FIELD_CONTENT_LOCATION, MIME_LEN_CONTENT_LOCATION, MIME_PRESENCE_CONTENT_LOCATION},
+            {MIME_FIELD_EXPIRES, MIME_LEN_EXPIRES, MIME_PRESENCE_EXPIRES},
+            {MIME_FIELD_CACHE_CONTROL, MIME_LEN_CACHE_CONTROL, MIME_PRESENCE_CACHE_CONTROL},
+            {MIME_FIELD_VARY, MIME_LEN_VARY, MIME_PRESENCE_VARY},
+          };
+
+          for (size_t i = 0; i < countof(fields); i++) {
+            if (base_response->presence(fields[i].presence)) {
+              MIMEField *field;
+              int len;
+              const char *value;
+
+              field = base_response->field_find(fields[i].name, fields[i].len);
               ink_assert(field != nullptr);
               value = field->value_get(&len);
-              outgoing_response->value_append(field_name[i], field_len[i], value, len,
0);
+              outgoing_response->value_append(fields[i].name, fields[i].len, value, len,
0);
             }
           }
         }

-- 
To stop receiving notification emails like this one, please contact
"commits@trafficserver.apache.org" <commits@trafficserver.apache.org>.

Mime
View raw message