[trafficserver] branch master updated: cachekey: capture cache key elements from headers

2018-08-14 Thread gancho
This is an automated email from the ASF dual-hosted git repository.

gancho pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/trafficserver.git


The following commit(s) were added to refs/heads/master by this push:
 new d49271b  cachekey: capture cache key elements from headers
d49271b is described below

commit d49271b167bca3ea9e7a1b0ac0c65c72512a85dc
Author: Gancho Tenev 
AuthorDate: Fri Jul 6 17:25:33 2018 -0700

cachekey: capture cache key elements from headers

--capture-header=:
captures elements from header  using 
and adds them to the cache key.
---
 doc/admin-guide/plugins/cachekey.en.rst |  29 ++--
 plugins/cachekey/cachekey.cc| 119 +---
 plugins/cachekey/cachekey.h |   4 ++
 plugins/cachekey/common.h   |   2 +
 plugins/cachekey/configs.cc |  52 ++
 plugins/cachekey/configs.h  |  14 +++-
 plugins/cachekey/pattern.cc |  12 
 plugins/cachekey/pattern.h  |   2 +
 8 files changed, 187 insertions(+), 47 deletions(-)

diff --git a/doc/admin-guide/plugins/cachekey.en.rst 
b/doc/admin-guide/plugins/cachekey.en.rst
index 958cdbe..0b631d5 100644
--- a/doc/admin-guide/plugins/cachekey.en.rst
+++ b/doc/admin-guide/plugins/cachekey.en.rst
@@ -110,14 +110,16 @@ Cache key structure and related plugin parameters
 
 ::
 
-  Optional components  | ┌───┐
-   | │ --include-headers │
-   | ├───┤
-  Default values if no | │ (empty)   |
-  optional components  | └───┘
+  Optional components  | ┌───┬┐
+   | │ --include-headers │  --capture-headers │
+   | ├┤
+  Default values if no | │ (empty)   |  (empty)   |
+  optional components  | └───┴┘
   configured   |
 
-* ``--include-headers`` (default: empty list) - comma separated list of 
headers to be added to the cache key. The list of headers defined by 
``--include-headers`` are always sorted before adding them to the cache  key.
+* ``--include-headers`` (default: empty list) - comma separated list of 
headers to be added to the cache key. The list of headers defined by 
``--include-headers`` are always sorted before adding them to the cache key.
+
+* ``--capture-header=:`` (default: empty) - 
captures elements from header  using  and adds 
them to the cache key.
 
 "Cookies" section
 ^
@@ -400,6 +402,21 @@ The following headers ``HeaderA`` and ``HeaderB`` will be 
used when constructing
 
   @plugin=cachekey.so @pparam=--include-headers=HeaderA,HeaderB
 
+The following would capture from the ``Authorization`` header and will add the 
captured element to the cache key ::
+
+  @plugin=cachekey.so \
+  
@pparam=--capture-header=Authorization:/AWS\s(?[^:]+).*/clientID:$1/"
+
+If the request looks like the following::
+
+  http://example-cdn.com/path/file
+  Authorization: AWS MKIARYMOG51PT0DLD:DLiWQ2lyS49H4Zyx34kW0URtg6s=
+
+Cache key would be set to::
+
+  /example-cdn.com/80/clientID:MKIARYMOG51PTCKQ0DLD/path/file
+
+
 HTTP Cookies
 
 
diff --git a/plugins/cachekey/cachekey.cc b/plugins/cachekey/cachekey.cc
index a31d628..c89b657 100644
--- a/plugins/cachekey/cachekey.cc
+++ b/plugins/cachekey/cachekey.cc
@@ -437,6 +437,61 @@ CacheKey::appendPath(Pattern &pathCapture, Pattern 
&pathCaptureUri)
   }
 }
 
+template 
+void
+CacheKey::processHeader(const String &name, const ConfigHeaders &config, T 
&dst,
+void (*fun)(const ConfigHeaders &config, const String 
&name_s, const String &value_s, T &captures))
+{
+  TSMLoc field;
+
+  for (field = TSMimeHdrFieldFind(_buf, _hdrs, name.c_str(), name.size()); 
field != TS_NULL_MLOC;
+   field = ::nextDuplicate(_buf, _hdrs, field)) {
+const char *value;
+int vlen;
+int count = TSMimeHdrFieldValuesCount(_buf, _hdrs, field);
+
+for (int i = 0; i < count; ++i) {
+  value = TSMimeHdrFieldValueStringGet(_buf, _hdrs, field, i, &vlen);
+  if (value == nullptr || vlen == 0) {
+CacheKeyDebug("missing value %d for header %s", i, name.c_str());
+continue;
+  }
+
+  String value_s(value, vlen);
+  fun(config, name, value_s, dst);
+}
+  }
+}
+
+template 
+void
+captureWholeHeaders(const ConfigHeaders &config, const String &name, const 
String &value, T &captures)
+{
+  CacheKeyDebug("processing header %s", name.c_str());
+  if (config.toBeAdded(name)) {
+String header;
+header.append(name).append(":").append(value);
+captures.insert(header);
+CacheKeyDebug("adding header '%s: %s'", name.c_str(), value.c_str());
+  } else {
+CacheKeyDebug("failed to find header '%s'", name.c_str());
+  }
+}
+
+template 
+void
+capture

[trafficserver] branch quic-latest updated: process early protected data during handshake

2018-08-14 Thread maskit
This is an automated email from the ASF dual-hosted git repository.

maskit pushed a commit to branch quic-latest
in repository https://gitbox.apache.org/repos/asf/trafficserver.git


The following commit(s) were added to refs/heads/quic-latest by this push:
 new 969ac3d  process early protected data during handshake
969ac3d is described below

commit 969ac3dc255b463dd79bd75f3a0eade7b099418f
Author: sunwei 
AuthorDate: Sat Aug 4 16:42:26 2018 +0800

process early protected data during handshake
---
 iocore/net/quic/QUICPacket.cc | 5 +
 iocore/net/quic/QUICPacket.h  | 1 +
 iocore/net/quic/QUICPacketReceiveQueue.cc | 9 +
 3 files changed, 15 insertions(+)

diff --git a/iocore/net/quic/QUICPacket.cc b/iocore/net/quic/QUICPacket.cc
index 4731b7e..82e0f78 100644
--- a/iocore/net/quic/QUICPacket.cc
+++ b/iocore/net/quic/QUICPacket.cc
@@ -1233,6 +1233,11 @@ QUICPacketFactory::set_hs_protocol(QUICHandshakeProtocol 
*hs_protocol)
   this->_hs_protocol = hs_protocol;
 }
 
+bool
+QUICPacketFactory::is_ready_to_create_protected_packet()
+{
+  return this->_hs_protocol->is_handshake_finished();
+}
 //
 // QUICPacketNumberGenerator
 //
diff --git a/iocore/net/quic/QUICPacket.h b/iocore/net/quic/QUICPacket.h
index 1aadc80..b43b4e4 100644
--- a/iocore/net/quic/QUICPacket.h
+++ b/iocore/net/quic/QUICPacket.h
@@ -401,6 +401,7 @@ public:
 ats_unique_buf payload, size_t 
len, bool retransmittable);
   void set_version(QUICVersion negotiated_version);
   void set_hs_protocol(QUICHandshakeProtocol *hs_protocol);
+  bool is_ready_to_create_protected_packet();
 
 private:
   QUICVersion _version= QUIC_SUPPORTED_VERSIONS[0];
diff --git a/iocore/net/quic/QUICPacketReceiveQueue.cc 
b/iocore/net/quic/QUICPacketReceiveQueue.cc
index fb09a87..9b0a837 100644
--- a/iocore/net/quic/QUICPacketReceiveQueue.cc
+++ b/iocore/net/quic/QUICPacketReceiveQueue.cc
@@ -156,6 +156,15 @@ QUICPacketReceiveQueue::dequeue(QUICPacketCreationResult 
&result)
   this->_offset  = 0;
 }
   } else {
+if (!this->_packet_factory.is_ready_to_create_protected_packet() && 
udp_packet) {
+  this->enqueue(udp_packet);
+  this->_payload.release();
+  this->_payload = nullptr;
+  this->_payload_len = 0;
+  this->_offset  = 0;
+  result = QUICPacketCreationResult::NOT_READY;
+  return quic_packet;
+}
 pkt= std::move(this->_payload);
 pkt_len= this->_payload_len;
 this->_payload = nullptr;