Updated Branches:
  refs/heads/master 025cd2796 -> 4a4c517e0

TS-1249: preserve gzip encoding in ESI plugin

These lines are removing "Accept-Encoding" from the requests that
the ESI plugin sent based on ESI include in the ESI response.
Essentially they are stopping the ESI include from using gzipped
for the response. Commenting this out give this choice back to user.
User can choose whether to have Accept-Encoding header or not in
his original request and the ESI include will also be fired with
the header if present.


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

Branch: refs/heads/master
Commit: 4a4c517e01d454e9490cea63ef7198c3d50461cd
Parents: 025cd27
Author: Shu Kit Chan <[email protected]>
Authored: Fri Aug 17 21:17:34 2012 -0700
Committer: James Peach <[email protected]>
Committed: Fri Aug 17 21:17:34 2012 -0700

----------------------------------------------------------------------
 .../esi/fetcher/HttpDataFetcherImpl.cc             |   65 ++++++++++++++-
 .../experimental/esi/fetcher/HttpDataFetcherImpl.h |    3 +
 plugins/experimental/esi/plugin.cc                 |    1 +
 3 files changed, 68 insertions(+), 1 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/trafficserver/blob/4a4c517e/plugins/experimental/esi/fetcher/HttpDataFetcherImpl.cc
----------------------------------------------------------------------
diff --git a/plugins/experimental/esi/fetcher/HttpDataFetcherImpl.cc 
b/plugins/experimental/esi/fetcher/HttpDataFetcherImpl.cc
index 09eda83..670a872 100644
--- a/plugins/experimental/esi/fetcher/HttpDataFetcherImpl.cc
+++ b/plugins/experimental/esi/fetcher/HttpDataFetcherImpl.cc
@@ -23,6 +23,7 @@
 
 #include "HttpDataFetcherImpl.h"
 #include "Utils.h"
+#include "gzip.h"
 
 #include <arpa/inet.h>
 
@@ -183,6 +184,23 @@ HttpDataFetcherImpl::handleFetchEvent(TSEvent event, void 
*edata) {
            list_iter != req_data.callback_objects.end(); ++list_iter) {
         (*list_iter)->processData(req_str.data(), req_str.size(), 
req_data.body, req_data.body_len);
       }
+
+      if (_checkHeaderValue(req_data.bufp, req_data.hdr_loc,
+                       TS_MIME_FIELD_CONTENT_ENCODING,
+                       TS_MIME_LEN_CONTENT_ENCODING,
+                       TS_HTTP_VALUE_GZIP, TS_HTTP_LEN_GZIP, false)) {
+        BufferList buf_list;
+        req_data.raw_response = "";
+        if (gunzip(req_data.body, req_data.body_len, buf_list)) {
+          for (BufferList::iterator iter = buf_list.begin(); iter != 
buf_list.end(); ++iter) {
+            req_data.raw_response.append(iter->data(),iter->size());
+          }
+          req_data.body_len = req_data.raw_response.size();
+          req_data.body = req_data.raw_response.data();
+        } else {
+          TSError("[%s] Error while gunzipping data", __FUNCTION__);
+        }
+      }
     } else {
       TSDebug(_debug_tag.c_str(), "[%s] Received non-OK status %d for request 
[%s]",
                __FUNCTION__, resp_status, req_str.data());
@@ -201,6 +219,44 @@ HttpDataFetcherImpl::handleFetchEvent(TSEvent event, void 
*edata) {
 }
 
 bool
+HttpDataFetcherImpl::_checkHeaderValue(TSMBuffer bufp, TSMLoc hdr_loc, const 
char *name, int name_len,
+                 const char *exp_value, int exp_value_len, bool prefix) const {
+  TSMLoc field_loc = TSMimeHdrFieldFind(bufp, hdr_loc, name, name_len);
+  if (!field_loc) {
+    return false;
+  }
+  bool retval = false;
+  if (exp_value && exp_value_len) {
+    const char *value;
+    int value_len;
+    int n_values = TSMimeHdrFieldValuesCount(bufp, hdr_loc, field_loc);
+    for (int i = 0; i < n_values; ++i) {
+      value = TSMimeHdrFieldValueStringGet(bufp, hdr_loc, field_loc, i, 
&value_len);
+      if ( NULL != value || value_len ) {
+        if (prefix) {
+          if ((value_len >= exp_value_len) &&
+              (strncasecmp(value, exp_value, exp_value_len) == 0)) {
+            retval = true;
+          }
+        } else if (Utils::areEqual(value, value_len, exp_value, 
exp_value_len)) {
+          retval = true;
+        }
+      } else {
+        TSDebug(_debug_tag.c_str(), "[%s] Error while getting value # %d of 
header [%.*s]", __FUNCTION__,
+                 i, name_len, name);
+      }
+      if (retval) {
+        break;
+      }
+    }
+  } else { // only presence required
+    retval = true;
+  }
+  TSHandleMLocRelease(bufp, hdr_loc, field_loc);
+  return retval;
+}
+
+bool
 HttpDataFetcherImpl::getData(const string &url, ResponseData &resp_data) const 
{
   UrlToContentMap::const_iterator iter = _pages.find(url);
   if (iter == _pages.end()) {
@@ -219,6 +275,7 @@ HttpDataFetcherImpl::getData(const string &url, 
ResponseData &resp_data) const {
     resp_data.clear();
     return false;
   }
+
   resp_data.set(req_data.body, req_data.body_len, req_data.bufp, 
req_data.hdr_loc);
   TSDebug(_debug_tag.c_str(), "[%s] Found data for URL [%s] of size %d 
starting with [%.5s]",
            __FUNCTION__, url.data(), req_data.body_len, req_data.body);
@@ -257,9 +314,15 @@ HttpDataFetcherImpl::getRequestStatus(const string &url) 
const {
 void
 HttpDataFetcherImpl::useHeader(const HttpHeader &header) {
   if (Utils::areEqual(header.name, header.name_len,
-                      TS_MIME_FIELD_ACCEPT_ENCODING, 
TS_MIME_LEN_ACCEPT_ENCODING)) {
+                      TS_MIME_FIELD_CONTENT_LENGTH, 
TS_MIME_LEN_CONTENT_LENGTH)) {
+    return;
+  }
+
+  if (Utils::areEqual(header.name, header.name_len,
+                      TS_MIME_FIELD_RANGE, TS_MIME_LEN_RANGE)) {
     return;
   }
+
   string name(header.name, header.name_len);
   string value(header.value, header.value_len);
   std::pair<StringHash::iterator, bool> result = 
_headers.insert(StringHash::value_type(name, value));

http://git-wip-us.apache.org/repos/asf/trafficserver/blob/4a4c517e/plugins/experimental/esi/fetcher/HttpDataFetcherImpl.h
----------------------------------------------------------------------
diff --git a/plugins/experimental/esi/fetcher/HttpDataFetcherImpl.h 
b/plugins/experimental/esi/fetcher/HttpDataFetcherImpl.h
index 726e20b..b27d327 100644
--- a/plugins/experimental/esi/fetcher/HttpDataFetcherImpl.h
+++ b/plugins/experimental/esi/fetcher/HttpDataFetcherImpl.h
@@ -96,6 +96,7 @@ private:
   // used to track a request that was made
   struct RequestData {
     std::string response;
+    std::string raw_response;
     const char *body;
     int body_len;
     CallbackObjectList callback_objects;
@@ -122,6 +123,8 @@ private:
   }
 
   bool _isFetchEvent(TSEvent event, int &base_event_id) const;
+  bool _checkHeaderValue(TSMBuffer bufp, TSMLoc hdr_loc, const char *name, int 
name_len, const char *exp_value, int exp_value_len, bool prefix) const;
+
 
   EsiLib::StringHash _headers;
   std::string _headers_str;

http://git-wip-us.apache.org/repos/asf/trafficserver/blob/4a4c517e/plugins/experimental/esi/plugin.cc
----------------------------------------------------------------------
diff --git a/plugins/experimental/esi/plugin.cc 
b/plugins/experimental/esi/plugin.cc
index 5e81152..f217a73 100644
--- a/plugins/experimental/esi/plugin.cc
+++ b/plugins/experimental/esi/plugin.cc
@@ -1012,6 +1012,7 @@ isTxnTransformable(TSHttpTxn txnp, bool is_cache_txn) {
     goto lReturn; // found internal header; no other detection required
   }
 
+  // allow response with specific status code to be transformable
   resp_status = TSHttpHdrStatusGet(bufp, hdr_loc);
   if (static_cast<int>(resp_status) == static_cast<int>(TS_ERROR)) {
     TSError("[%s] Error while getting http status", __FUNCTION__);

Reply via email to