trafficserver-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bc...@apache.org
Subject [trafficserver] branch master updated: Adding custom method support and bug fixes
Date Fri, 02 Feb 2018 21:35:05 GMT
This is an automated email from the ASF dual-hosted git repository.

bcall 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 21cdbda  Adding custom method support and bug fixes
21cdbda is described below

commit 21cdbdaef560df0e21e5c772d7069eee61d422c7
Author: Jesse Zhang <macisasandwich@gmail.com>
AuthorDate: Fri Feb 2 11:05:37 2018 -0600

    Adding custom method support and bug fixes
---
 tests/tools/sessionvalidation/sessionvalidation.py | 12 +++---
 tests/tools/traffic-replay/NonSSL.py               |  5 +++
 tests/tools/traffic-replay/SSLReplay.py            | 43 +++++++++++++---------
 tests/tools/traffic-replay/extractHeader.py        | 21 ++++++++++-
 4 files changed, 56 insertions(+), 25 deletions(-)

diff --git a/tests/tools/sessionvalidation/sessionvalidation.py b/tests/tools/sessionvalidation/sessionvalidation.py
index 101e27b..5c926ea 100644
--- a/tests/tools/sessionvalidation/sessionvalidation.py
+++ b/tests/tools/sessionvalidation/sessionvalidation.py
@@ -23,7 +23,9 @@ import sessionvalidation.transaction as transaction
 import sessionvalidation.request as request
 import sessionvalidation.response as response
 
-valid_HTTP_request_methods = ['GET', 'POST', 'HEAD']
+# valid_HTTP_request_methods = ['GET', 'POST', 'HEAD']
+# custom_HTTP_request_methods = ['PULL']  # transaction monitor plugin for ATS may have custom
methods
+allowed_HTTP_request_methods = ['GET', 'POST', 'HEAD', 'PULL']
 G_CUSTOM_METHODS = False
 G_VERBOSE_LOG = True
 
@@ -156,7 +158,6 @@ class SessionValidator(object):
         retval = True
 
         #valid_HTTP_request_methods = ['GET', 'HEAD', 'POST', 'PUT', 'DELETE', 'TRACE', 'OPTIONS',
'CONNECT', 'PATCH']
-        custom_HTTP_request_methods = ['PULL']  # transaction monitor plugin for ATS may
have custom methods
         # we can later uncomment the previous line to support more HTTP methods
         valid_HTTP_versions = ['HTTP/1.0', 'HTTP/1.1', 'HTTP/2.0']
 
@@ -171,10 +172,9 @@ class SessionValidator(object):
             elif float(txn_req.getTimestamp()) <= 0:
                 _verbose_print("invalid transaction request timestamp")
                 retval = False
-            elif txn_req.getHeaders().split()[0] not in valid_HTTP_request_methods:
-                if G_CUSTOM_METHODS and txn_req.getHeaders().split()[0] not in custom_HTTP_request_methods:
-                    _verbose_print("invalid HTTP method for transaction {0}".format(txn_req.getHeaders().split()[0]))
-                    retval = False
+            elif txn_req.getHeaders().split()[0] not in allowed_HTTP_request_methods:
+                _verbose_print("invalid HTTP method for transaction {0}".format(txn_req.getHeaders().split()[0]))
+                retval = False
             elif not txn_req.getHeaders().endswith("\r\n\r\n"):
                 _verbose_print("transaction request headers didn't end with \\r\\n\\r\\n")
                 retval = False
diff --git a/tests/tools/traffic-replay/NonSSL.py b/tests/tools/traffic-replay/NonSSL.py
index 9685bf2..60525bc 100644
--- a/tests/tools/traffic-replay/NonSSL.py
+++ b/tests/tools/traffic-replay/NonSSL.py
@@ -112,6 +112,11 @@ def txn_replay(session_filename, txn, proxy, result_queue, request_session):
                 txn_req_headers), headers=txn_req_headers_dict, data=body)
             responseHeaders = r1.headers
             responseContent = r1.content
+        else:   # EXPERIMENTAL
+            r1 = request_session.request(method, extractHeader.extract_GET_path(
+                txn_req_headers), headers=txn_req_headers_dict, data=body)
+            responseHeaders = r1.headers
+            responseContent = r1.content
 
             #gzip_file = gzip.GzipFile(fileobj=responseContent)
             #shutil.copyfileobj(gzip_file, f)
diff --git a/tests/tools/traffic-replay/SSLReplay.py b/tests/tools/traffic-replay/SSLReplay.py
index cc0d94e..bf49a60 100644
--- a/tests/tools/traffic-replay/SSLReplay.py
+++ b/tests/tools/traffic-replay/SSLReplay.py
@@ -21,6 +21,7 @@ import http.client
 import socket
 import ssl
 import pprint
+# import gevent
 import requests
 import os
 #import threading
@@ -29,6 +30,7 @@ from multiprocessing import current_process
 import sessionvalidation.sessionvalidation as sv
 import lib.result as result
 import extractHeader
+# from gevent import monkey, sleep
 from threading import Thread
 import mainProcess
 import json
@@ -125,24 +127,32 @@ def txn_replay(session_filename, txn, proxy, result_queue, request_session):
             nBytes = int(txn_req_headers_dict['Content-Length'])
             body = createDummyBodywithLength(nBytes)
         #print("request session is",id(request_session))
+        
+        # NOTE: request_session here is actually python's HTTPSConnection, which is different
from that in NonSSL, which uses the requests library -_-
         if method == 'GET':
-            r1 = request_session.request('GET', extractHeader.extract_GET_path(
-                txn_req_headers), headers=txn_req_headers_dict, data=body)
-            responseHeaders = r1.headers
-            responseContent = r1.content  # byte array
+            request_session.request('GET', extractHeader.extract_GET_path(
+                txn_req_headers), headers=txn_req_headers_dict, body=body)
+            r1 = request_session.getresponse()
+            responseContent = r1.read()  # byte array
 
         elif method == 'POST':
-            r1 = request_session.request('POST', extractHeader.extract_GET_path(
-                txn_req_headers), headers=txn_req_headers_dict, data=body)
-            responseHeaders = r1.headers
-            responseContent = r1.content
+            request_session.request('POST', extractHeader.extract_GET_path(
+                txn_req_headers), headers=txn_req_headers_dict, body=body)
+            r1 = request_session.getresponse()
+            responseContent = r1.read()
 
         elif method == 'HEAD':
-            r1 = request_session.request('HEAD', extractHeader.extract_GET_path(
-                txn_req_headers), headers=txn_req_headers_dict, data=body)
-            responseHeaders = r1.headers
-            responseContent = r1.content
-
+            request_session.request('HEAD', extractHeader.extract_GET_path(
+                txn_req_headers), headers=txn_req_headers_dict, body=body)
+            r1 = request_session.getresponse()
+            responseContent = r1.read()
+        else:   # EXPERIMENTAL
+            request_session.request(method, extractHeader.extract_GET_path(
+                txn_req_headers), headers=txn_req_headers_dict, body=body)
+            r1 = request_session.getresponse()
+            responseContent = r1.read()
+
+        responseHeaders = extractHeader.responseHeaderTuple_to_dict(r1.getheaders())
         expected = extractHeader.responseHeader_to_dict(resp.getHeaders())
         # print("------------EXPECTED-----------")
         # print(expected)
@@ -152,7 +162,7 @@ def txn_replay(session_filename, txn, proxy, result_queue, request_session):
         if mainProcess.verbose:
             expected_output_split = resp.getHeaders().split('\r\n')[0].split(' ', 2)
             expected_output = (int(expected_output_split[1]), str(expected_output_split[2]))
-            r = result.Result(session_filename, expected_output[0], r1.status_code, responseContent)
+            r = result.Result(session_filename, expected_output[0], r1.status, responseContent)
             b_res, res = r.getResult(responseHeaders, expected, colorize=True)
             print(res)
 
@@ -201,8 +211,7 @@ def session_replay(input, proxy, result_queue):
             txn_req_headers = req.getHeaders()
             txn_req_headers_dict = extractHeader.header_to_dict(txn_req_headers)
             sc = ssl.SSLContext(protocol=ssl.PROTOCOL_SSLv23)
-            if Config.ca_certs != None and Config.keyfile != None:
-                sc.load_cert_chain(Config.ca_certs, keyfile=Config.keyfile)
+            sc.load_cert_chain(Config.ca_certs, keyfile=Config.keyfile)
             conn = ProxyHTTPSConnection(Config.proxy_host, Config.proxy_ssl_port, cert_file=Config.ca_certs,
                                         key_file=Config.keyfile, context=sc, server_name=txn_req_headers_dict['Host'])
             for txn in session.getTransactionIter():
@@ -215,7 +224,7 @@ def session_replay(input, proxy, result_queue):
             #sslSocket.bStop = False
 
         bSTOP = True
-        #print("stopping now")
+        print("stopping now")
         input.put('STOP')
         break
 
diff --git a/tests/tools/traffic-replay/extractHeader.py b/tests/tools/traffic-replay/extractHeader.py
index c8f7961..a815183 100644
--- a/tests/tools/traffic-replay/extractHeader.py
+++ b/tests/tools/traffic-replay/extractHeader.py
@@ -17,7 +17,7 @@
 #  See the License for the specific language governing permissions and
 #  limitations under the License.
 
-import sessionvalidation
+import sessionvalidation.sessionvalidation as sv
 
 
 def extract_txn_req_method(headers):
@@ -34,6 +34,16 @@ def extract_host(headers):
             return line.split(' ')[1]
     return "notfound"
 
+def responseHeaderTuple_to_dict(header):
+    header_dict = {}
+
+    for key, val in header:
+        if key.lower() in header_dict:
+            header_dict[key.lower()] += ", {0}".format(val)
+        else:
+            header_dict[key.lower()] = val
+
+    return header_dict
 
 def responseHeader_to_dict(header):
     headerFields = header.split('\r\n', 1)[1]
@@ -59,7 +69,14 @@ def header_to_dict(header):
     header = [x for x in header if (x != u'')]
     headers = {}
     for line in header:
-        if 'GET' in line or 'POST' in line or 'HEAD' in line:     # ignore initial request
line
+        should_skip = False
+
+        # we have to ignore the intital request line with the HTTP method in it
+        for method in sv.allowed_HTTP_request_methods:
+            if method in line:
+                should_skip = True
+
+        if should_skip:     # ignore initial request line
             continue
 
         split_here = line.find(":")

-- 
To stop receiving notification emails like this one, please contact
bcall@apache.org.

Mime
View raw message