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/08/19 18:33:06 UTC

git commit: TS-2902: Allow POST requests without a Content-Length header

Repository: trafficserver
Updated Branches:
  refs/heads/master 674bc2279 -> db3de1894


TS-2902: Allow POST requests without a Content-Length header


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

Branch: refs/heads/master
Commit: db3de1894901d4ec9e2bc7983dac48941b104ffc
Parents: 674bc22
Author: Masakazu Kitajo <mk...@yahoo-corp.jp>
Authored: Tue Aug 19 09:32:41 2014 -0700
Committer: Bryan Call <bc...@apache.org>
Committed: Tue Aug 19 09:32:41 2014 -0700

----------------------------------------------------------------------
 CHANGES                    |  2 ++
 lib/ts/apidefs.h.in        |  1 +
 mgmt/RecordsConfig.cc      |  2 ++
 proxy/InkAPI.cc            | 15 +++++++++++++--
 proxy/http/HttpConfig.cc   |  3 +++
 proxy/http/HttpConfig.h    |  7 ++++++-
 proxy/http/HttpTransact.cc |  5 +++--
 7 files changed, 30 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/trafficserver/blob/db3de189/CHANGES
----------------------------------------------------------------------
diff --git a/CHANGES b/CHANGES
index 9f73841..2ecd621 100644
--- a/CHANGES
+++ b/CHANGES
@@ -1,6 +1,8 @@
                                                          -*- coding: utf-8 -*-
 Changes with Apache Traffic Server 5.1.0
 
+  *) [TS-2902] Allow POST requests without a Content-Length header
+
   *) [TS-2423] Add option for server sessions that use auth headers that can
    be placed into the shared pool
 

http://git-wip-us.apache.org/repos/asf/trafficserver/blob/db3de189/lib/ts/apidefs.h.in
----------------------------------------------------------------------
diff --git a/lib/ts/apidefs.h.in b/lib/ts/apidefs.h.in
index 130b91b..b9a7fdd 100644
--- a/lib/ts/apidefs.h.in
+++ b/lib/ts/apidefs.h.in
@@ -732,6 +732,7 @@ extern "C"
     TS_CONFIG_HTTP_CACHE_OPEN_READ_RETRY_TIME,
     TS_CONFIG_HTTP_CACHE_MAX_OPEN_READ_RETRIES,
     TS_CONFIG_HTTP_CACHE_RANGE_WRITE,
+    TS_CONFIG_HTTP_POST_CHECK_CONTENT_LENGTH_ENABLED,
     TS_CONFIG_LAST_ENTRY
   } TSOverridableConfigKey;
 

http://git-wip-us.apache.org/repos/asf/trafficserver/blob/db3de189/mgmt/RecordsConfig.cc
----------------------------------------------------------------------
diff --git a/mgmt/RecordsConfig.cc b/mgmt/RecordsConfig.cc
index 7aa6f80..a3fb7fd 100644
--- a/mgmt/RecordsConfig.cc
+++ b/mgmt/RecordsConfig.cc
@@ -414,6 +414,8 @@ RecordElement RecordsConfig[] = {
   ,
   {RECT_CONFIG, "proxy.config.http.flow_control.low_water", RECD_INT, "0", RECU_DYNAMIC, RR_NULL, RECC_NULL, NULL, RECA_NULL}
   ,
+  {RECT_CONFIG, "proxy.config.http.post.check.content_length.enabled", RECD_INT, "1", RECU_DYNAMIC, RR_NULL, RECC_INT, "[0-1]", RECA_NULL}
+  ,
   //       # Send http11 requests
   //       #
   //       #   0 - Never

http://git-wip-us.apache.org/repos/asf/trafficserver/blob/db3de189/proxy/InkAPI.cc
----------------------------------------------------------------------
diff --git a/proxy/InkAPI.cc b/proxy/InkAPI.cc
index 157df6f..b11cece 100644
--- a/proxy/InkAPI.cc
+++ b/proxy/InkAPI.cc
@@ -7816,6 +7816,9 @@ _conf_to_memberp(TSOverridableConfigKey conf,
   case TS_CONFIG_HTTP_CACHE_RANGE_WRITE:
     ret = &overridableHttpConfig->cache_range_write;
     break;
+  case TS_CONFIG_HTTP_POST_CHECK_CONTENT_LENGTH_ENABLED:
+    ret = &overridableHttpConfig->post_check_content_length_enabled;
+    break;
 
     // This helps avoiding compiler warnings, yet detect unhandled enum members.
   case TS_CONFIG_NULL:
@@ -8382,8 +8385,16 @@ TSHttpTxnConfigFind(const char* name, int length, TSOverridableConfigKey *conf,
     break;
 
   case 51:
-    if (!strncmp(name, "proxy.config.http.keep_alive_no_activity_timeout_in", length))
-      cnf = TS_CONFIG_HTTP_KEEP_ALIVE_NO_ACTIVITY_TIMEOUT_IN;
+    switch (name[length-1]) {
+    case 'n':
+      if (!strncmp(name, "proxy.config.http.keep_alive_no_activity_timeout_in", length))
+        cnf = TS_CONFIG_HTTP_KEEP_ALIVE_NO_ACTIVITY_TIMEOUT_IN;
+      break;
+    case 'd':
+      if (!strncmp(name, "proxy.config.http.post.check.content_length.enabled", length))
+        cnf = TS_CONFIG_HTTP_POST_CHECK_CONTENT_LENGTH_ENABLED;
+      break;
+    }
     break;
 
   case 52:

http://git-wip-us.apache.org/repos/asf/trafficserver/blob/db3de189/proxy/http/HttpConfig.cc
----------------------------------------------------------------------
diff --git a/proxy/http/HttpConfig.cc b/proxy/http/HttpConfig.cc
index 88433a9..dd08780 100644
--- a/proxy/http/HttpConfig.cc
+++ b/proxy/http/HttpConfig.cc
@@ -1281,6 +1281,7 @@ HttpConfig::startup()
   HttpEstablishStaticConfigByte(c.oride.flow_control_enabled, "proxy.config.http.flow_control.enabled");
   HttpEstablishStaticConfigLongLong(c.oride.flow_high_water_mark, "proxy.config.http.flow_control.high_water");
   HttpEstablishStaticConfigLongLong(c.oride.flow_low_water_mark, "proxy.config.http.flow_control.low_water");
+  HttpEstablishStaticConfigByte(c.oride.post_check_content_length_enabled, "proxy.config.http.post.check.content_length.enabled");
 //HttpEstablishStaticConfigByte(c.oride.share_server_sessions, "proxy.config.http.share_server_sessions");
 
   // 4.2 Backwards compatibility
@@ -1539,6 +1540,8 @@ HttpConfig::reconfigure()
   params->oride.chunking_enabled = INT_TO_BOOL(m_master.oride.chunking_enabled);
   params->oride.http_chunking_size = m_master.oride.http_chunking_size;
 
+  params->oride.post_check_content_length_enabled = INT_TO_BOOL(m_master.oride.post_check_content_length_enabled);
+
   params->oride.flow_control_enabled = INT_TO_BOOL(m_master.oride.flow_control_enabled);
   params->oride.flow_high_water_mark = m_master.oride.flow_high_water_mark;
   params->oride.flow_low_water_mark = m_master.oride.flow_low_water_mark;

http://git-wip-us.apache.org/repos/asf/trafficserver/blob/db3de189/proxy/http/HttpConfig.h
----------------------------------------------------------------------
diff --git a/proxy/http/HttpConfig.h b/proxy/http/HttpConfig.h
index c465043..282b133 100644
--- a/proxy/http/HttpConfig.h
+++ b/proxy/http/HttpConfig.h
@@ -409,7 +409,7 @@ struct OverridableHttpConfigParams {
       negative_caching_lifetime(1800), negative_revalidating_lifetime(1800),
       sock_recv_buffer_size_out(0), sock_send_buffer_size_out(0), sock_option_flag_out(0),
       sock_packet_mark_out(0), sock_packet_tos_out(0), server_tcp_init_cwnd(0),
-      request_hdr_max_size(131072), response_hdr_max_size(131072),
+      request_hdr_max_size(131072), response_hdr_max_size(131072), post_check_content_length_enabled(1),
       cache_heuristic_min_lifetime(3600), cache_heuristic_max_lifetime(86400),
       cache_guaranteed_min_lifetime(0), cache_guaranteed_max_lifetime(31536000), cache_max_stale_age(604800),
       keep_alive_no_activity_timeout_in(115), keep_alive_no_activity_timeout_out(120),
@@ -542,6 +542,11 @@ struct OverridableHttpConfigParams {
   MgmtInt request_hdr_max_size;
   MgmtInt response_hdr_max_size;
 
+  ////////////////////////
+  // Check Post request //
+  ////////////////////////
+  MgmtByte post_check_content_length_enabled;
+
   /////////////////////
   // cache variables //
   /////////////////////

http://git-wip-us.apache.org/repos/asf/trafficserver/blob/db3de189/proxy/http/HttpTransact.cc
----------------------------------------------------------------------
diff --git a/proxy/http/HttpTransact.cc b/proxy/http/HttpTransact.cc
index a734b92..6663581 100644
--- a/proxy/http/HttpTransact.cc
+++ b/proxy/http/HttpTransact.cc
@@ -5212,7 +5212,8 @@ HttpTransact::RequestError_t HttpTransact::check_request_validity(State* s, HTTP
     if ((scheme == URL_WKSIDX_HTTP || scheme == URL_WKSIDX_HTTPS) &&
         (method == HTTP_WKSIDX_POST || method == HTTP_WKSIDX_PUSH || method == HTTP_WKSIDX_PUT) &&
         s->client_info.transfer_encoding != CHUNKED_ENCODING) {
-      if (!incoming_hdr->presence(MIME_PRESENCE_CONTENT_LENGTH)) {
+      if ((s->txn_conf->post_check_content_length_enabled) &&
+          !incoming_hdr->presence(MIME_PRESENCE_CONTENT_LENGTH)) {
         return NO_POST_CONTENT_LENGTH;
       }
       if (HTTP_UNDEFINED_CL == s->hdr_info.request_content_length) {
@@ -6307,7 +6308,7 @@ HttpTransact::is_request_valid(State* s, HTTPHdr* incoming_request)
     {
       DebugTxn("http_trans", "[is_request_valid] post request without content length");
       SET_VIA_STRING(VIA_DETAIL_TUNNEL, VIA_DETAIL_TUNNEL_NO_FORWARD);
-      build_error_response(s, HTTP_STATUS_BAD_REQUEST, "Content Length Required", "request#no_content_length", NULL);
+      build_error_response(s, HTTP_STATUS_LENGTH_REQUIRED, "Content Length Required", "request#no_content_length", NULL);
       return false;
     }
   case UNACCEPTABLE_TE_REQUIRED: