[GitHub] [qpid-dispatch] kgiusti commented on a change in pull request #1097: DISPATCH-2029: Added a base class and moved some of the http1 adaptor…

2021-04-07 Thread GitBox


kgiusti commented on a change in pull request #1097:
URL: https://github.com/apache/qpid-dispatch/pull/1097#discussion_r609034137



##
File path: tests/system_tests_http1_base.py
##
@@ -0,0 +1,1187 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+import socket
+import uuid
+from threading import Thread
+
+from time import sleep
+try:
+from http.server import HTTPServer, BaseHTTPRequestHandler
+from http.client import HTTPConnection
+from http.client import HTTPException
+except ImportError:
+from BaseHTTPServer import HTTPServer, BaseHTTPRequestHandler
+from httplib import HTTPConnection, HTTPException
+
+from system_test import TestCase, TIMEOUT, Logger, Qdrouterd
+
+
+class RequestHandler(BaseHTTPRequestHandler):
+"""
+Dispatches requests received by the HTTPServer based on the method
+"""
+protocol_version = 'HTTP/1.1'
+
+def _execute_request(self, tests):
+for req, resp, val in tests:
+if req.target == self.path:
+xhdrs = None
+if "test-echo" in self.headers:
+xhdrs = {"test-echo":
+ self.headers["test-echo"]}
+
+self._consume_body()
+if not isinstance(resp, list):
+resp = [resp]
+for r in resp:
+r.send_response(self, extra_headers=xhdrs)
+self.server.request_count += 1
+return
+self.send_error(404, "Not Found")
+
+def do_GET(self):
+self._execute_request(self.server.system_tests["GET"])
+
+def do_HEAD(self):
+self._execute_request(self.server.system_tests["HEAD"])
+
+def do_POST(self):
+if self.path == "/SHUTDOWN":
+self.send_response(200, "OK")
+self.send_header("Content-Length", "13")
+self.end_headers()
+self.wfile.write(b'Server Closed')
+self.wfile.flush()
+self.close_connection = True
+self.server.server_killed = True
+return
+self._execute_request(self.server.system_tests["POST"])
+
+def do_PUT(self):
+self._execute_request(self.server.system_tests["PUT"])
+
+# these overrides just quiet the test output
+# comment them out to help debug:
+def log_request(self, code=None, size=None):
+pass
+
+def log_message(self, format=None, *args):
+pass
+
+def _consume_body(self):
+"""
+Read the entire body off the rfile.  This must be done to allow
+multiple requests on the same socket
+"""
+if self.command == 'HEAD':
+return b''
+
+for key, value in self.headers.items():
+if key.lower() == 'content-length':
+return self.rfile.read(int(value))
+
+if key.lower() == 'transfer-encoding'  \
+   and 'chunked' in value.lower():
+body = b''
+while True:
+header = self.rfile.readline().strip().split(b';')[0]
+hlen = int(header, base=16)
+if hlen > 0:
+data = self.rfile.read(hlen + 2)  # 2 = \r\n
+body += data[:-2]
+else:
+self.rfile.readline()  # discard last \r\n
+break
+return body
+return self.rfile.read()
+
+
+class RequestHandler10(RequestHandler):
+"""
+RequestHandler that forces the server to use HTTP version 1.0 semantics
+"""
+protocol_version = 'HTTP/1.0'
+
+
+class MyHTTPServer(HTTPServer):
+"""
+Adds a switch to the HTTPServer to allow it to exit gracefully
+"""
+
+def __init__(self, addr, handler_cls, testcases):
+self.system_tests = testcases
+self.request_count = 0
+HTTPServer.__init__(self, addr, handler_cls)
+
+def server_close(self):
+try:
+# force immediate close of listening socket
+self.socket.shutdown(socket.SHUT_RDWR)
+except Exception:
+pass
+HTTPServer.server_close(self)
+
+
+class ThreadedTestClient(object):
+"""
+   

[GitHub] [qpid-dispatch] kgiusti commented on a change in pull request #1097: DISPATCH-2029: Added a base class and moved some of the http1 adaptor…

2021-04-07 Thread GitBox


kgiusti commented on a change in pull request #1097:
URL: https://github.com/apache/qpid-dispatch/pull/1097#discussion_r608990879



##
File path: tests/system_tests_http1_base.py
##
@@ -0,0 +1,1187 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+import socket
+import uuid
+from threading import Thread
+
+from time import sleep
+try:
+from http.server import HTTPServer, BaseHTTPRequestHandler
+from http.client import HTTPConnection
+from http.client import HTTPException
+except ImportError:
+from BaseHTTPServer import HTTPServer, BaseHTTPRequestHandler
+from httplib import HTTPConnection, HTTPException
+
+from system_test import TestCase, TIMEOUT, Logger, Qdrouterd
+
+
+class RequestHandler(BaseHTTPRequestHandler):
+"""
+Dispatches requests received by the HTTPServer based on the method
+"""
+protocol_version = 'HTTP/1.1'
+
+def _execute_request(self, tests):
+for req, resp, val in tests:
+if req.target == self.path:
+xhdrs = None
+if "test-echo" in self.headers:
+xhdrs = {"test-echo":
+ self.headers["test-echo"]}
+
+self._consume_body()
+if not isinstance(resp, list):
+resp = [resp]
+for r in resp:
+r.send_response(self, extra_headers=xhdrs)
+self.server.request_count += 1
+return
+self.send_error(404, "Not Found")
+
+def do_GET(self):
+self._execute_request(self.server.system_tests["GET"])
+
+def do_HEAD(self):
+self._execute_request(self.server.system_tests["HEAD"])
+
+def do_POST(self):
+if self.path == "/SHUTDOWN":
+self.send_response(200, "OK")
+self.send_header("Content-Length", "13")
+self.end_headers()
+self.wfile.write(b'Server Closed')
+self.wfile.flush()
+self.close_connection = True
+self.server.server_killed = True
+return
+self._execute_request(self.server.system_tests["POST"])
+
+def do_PUT(self):
+self._execute_request(self.server.system_tests["PUT"])
+
+# these overrides just quiet the test output
+# comment them out to help debug:
+def log_request(self, code=None, size=None):
+pass
+
+def log_message(self, format=None, *args):
+pass
+
+def _consume_body(self):
+"""
+Read the entire body off the rfile.  This must be done to allow
+multiple requests on the same socket
+"""
+if self.command == 'HEAD':
+return b''
+
+for key, value in self.headers.items():
+if key.lower() == 'content-length':
+return self.rfile.read(int(value))
+
+if key.lower() == 'transfer-encoding'  \
+   and 'chunked' in value.lower():
+body = b''
+while True:
+header = self.rfile.readline().strip().split(b';')[0]
+hlen = int(header, base=16)
+if hlen > 0:
+data = self.rfile.read(hlen + 2)  # 2 = \r\n
+body += data[:-2]
+else:
+self.rfile.readline()  # discard last \r\n
+break
+return body
+return self.rfile.read()
+
+
+class RequestHandler10(RequestHandler):
+"""
+RequestHandler that forces the server to use HTTP version 1.0 semantics
+"""
+protocol_version = 'HTTP/1.0'
+
+
+class MyHTTPServer(HTTPServer):
+"""
+Adds a switch to the HTTPServer to allow it to exit gracefully
+"""
+
+def __init__(self, addr, handler_cls, testcases):
+self.system_tests = testcases
+self.request_count = 0
+HTTPServer.__init__(self, addr, handler_cls)
+
+def server_close(self):
+try:
+# force immediate close of listening socket
+self.socket.shutdown(socket.SHUT_RDWR)
+except Exception:
+pass
+HTTPServer.server_close(self)
+
+
+class ThreadedTestClient(object):
+"""
+   

[GitHub] [qpid-dispatch] kgiusti commented on a change in pull request #1097: DISPATCH-2029: Added a base class and moved some of the http1 adaptor…

2021-04-07 Thread GitBox


kgiusti commented on a change in pull request #1097:
URL: https://github.com/apache/qpid-dispatch/pull/1097#discussion_r608990009



##
File path: tests/system_tests_http1_base.py
##
@@ -0,0 +1,1187 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+import socket
+import uuid
+from threading import Thread
+
+from time import sleep
+try:
+from http.server import HTTPServer, BaseHTTPRequestHandler
+from http.client import HTTPConnection
+from http.client import HTTPException
+except ImportError:
+from BaseHTTPServer import HTTPServer, BaseHTTPRequestHandler
+from httplib import HTTPConnection, HTTPException
+
+from system_test import TestCase, TIMEOUT, Logger, Qdrouterd
+
+
+class RequestHandler(BaseHTTPRequestHandler):
+"""
+Dispatches requests received by the HTTPServer based on the method
+"""
+protocol_version = 'HTTP/1.1'
+
+def _execute_request(self, tests):
+for req, resp, val in tests:
+if req.target == self.path:
+xhdrs = None
+if "test-echo" in self.headers:
+xhdrs = {"test-echo":
+ self.headers["test-echo"]}
+
+self._consume_body()
+if not isinstance(resp, list):
+resp = [resp]
+for r in resp:
+r.send_response(self, extra_headers=xhdrs)
+self.server.request_count += 1
+return
+self.send_error(404, "Not Found")
+
+def do_GET(self):
+self._execute_request(self.server.system_tests["GET"])
+
+def do_HEAD(self):
+self._execute_request(self.server.system_tests["HEAD"])
+
+def do_POST(self):
+if self.path == "/SHUTDOWN":
+self.send_response(200, "OK")
+self.send_header("Content-Length", "13")
+self.end_headers()
+self.wfile.write(b'Server Closed')
+self.wfile.flush()
+self.close_connection = True
+self.server.server_killed = True
+return
+self._execute_request(self.server.system_tests["POST"])
+
+def do_PUT(self):
+self._execute_request(self.server.system_tests["PUT"])
+
+# these overrides just quiet the test output
+# comment them out to help debug:
+def log_request(self, code=None, size=None):
+pass
+
+def log_message(self, format=None, *args):
+pass
+
+def _consume_body(self):
+"""
+Read the entire body off the rfile.  This must be done to allow
+multiple requests on the same socket
+"""
+if self.command == 'HEAD':
+return b''
+
+for key, value in self.headers.items():
+if key.lower() == 'content-length':
+return self.rfile.read(int(value))
+
+if key.lower() == 'transfer-encoding'  \
+   and 'chunked' in value.lower():
+body = b''
+while True:
+header = self.rfile.readline().strip().split(b';')[0]
+hlen = int(header, base=16)
+if hlen > 0:
+data = self.rfile.read(hlen + 2)  # 2 = \r\n
+body += data[:-2]
+else:
+self.rfile.readline()  # discard last \r\n
+break
+return body
+return self.rfile.read()
+
+
+class RequestHandler10(RequestHandler):
+"""
+RequestHandler that forces the server to use HTTP version 1.0 semantics
+"""
+protocol_version = 'HTTP/1.0'
+
+
+class MyHTTPServer(HTTPServer):
+"""
+Adds a switch to the HTTPServer to allow it to exit gracefully
+"""
+
+def __init__(self, addr, handler_cls, testcases):
+self.system_tests = testcases
+self.request_count = 0
+HTTPServer.__init__(self, addr, handler_cls)
+
+def server_close(self):
+try:
+# force immediate close of listening socket
+self.socket.shutdown(socket.SHUT_RDWR)
+except Exception:
+pass
+HTTPServer.server_close(self)
+
+
+class ThreadedTestClient(object):
+"""
+   

[GitHub] [qpid-dispatch] kgiusti commented on a change in pull request #1097: DISPATCH-2029: Added a base class and moved some of the http1 adaptor…

2021-04-07 Thread GitBox


kgiusti commented on a change in pull request #1097:
URL: https://github.com/apache/qpid-dispatch/pull/1097#discussion_r609023607



##
File path: tests/system_tests_http1_base.py
##
@@ -0,0 +1,1187 @@
+#

Review comment:
   Hmmm... I think this file shouldn't be a "system_tests_*" file since it 
does not define any TestCases.  It defines a set of HTTP/1.x tests that are 
shared between the http1_adaptor TestCases and http1_over_tcp TestCases.
   
   Name this fine something like http1_tests.py instead otherwise I think 
people will be tempted to add HTTP/1.x TestCases here instead of in the proper 
system_tests_*.py files. 




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org



-
To unsubscribe, e-mail: dev-unsubscr...@qpid.apache.org
For additional commands, e-mail: dev-h...@qpid.apache.org



[GitHub] [qpid-dispatch] kgiusti commented on a change in pull request #1097: DISPATCH-2029: Added a base class and moved some of the http1 adaptor…

2021-04-07 Thread GitBox


kgiusti commented on a change in pull request #1097:
URL: https://github.com/apache/qpid-dispatch/pull/1097#discussion_r608990879



##
File path: tests/system_tests_http1_base.py
##
@@ -0,0 +1,1187 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+import socket
+import uuid
+from threading import Thread
+
+from time import sleep
+try:
+from http.server import HTTPServer, BaseHTTPRequestHandler
+from http.client import HTTPConnection
+from http.client import HTTPException
+except ImportError:
+from BaseHTTPServer import HTTPServer, BaseHTTPRequestHandler
+from httplib import HTTPConnection, HTTPException
+
+from system_test import TestCase, TIMEOUT, Logger, Qdrouterd
+
+
+class RequestHandler(BaseHTTPRequestHandler):
+"""
+Dispatches requests received by the HTTPServer based on the method
+"""
+protocol_version = 'HTTP/1.1'
+
+def _execute_request(self, tests):
+for req, resp, val in tests:
+if req.target == self.path:
+xhdrs = None
+if "test-echo" in self.headers:
+xhdrs = {"test-echo":
+ self.headers["test-echo"]}
+
+self._consume_body()
+if not isinstance(resp, list):
+resp = [resp]
+for r in resp:
+r.send_response(self, extra_headers=xhdrs)
+self.server.request_count += 1
+return
+self.send_error(404, "Not Found")
+
+def do_GET(self):
+self._execute_request(self.server.system_tests["GET"])
+
+def do_HEAD(self):
+self._execute_request(self.server.system_tests["HEAD"])
+
+def do_POST(self):
+if self.path == "/SHUTDOWN":
+self.send_response(200, "OK")
+self.send_header("Content-Length", "13")
+self.end_headers()
+self.wfile.write(b'Server Closed')
+self.wfile.flush()
+self.close_connection = True
+self.server.server_killed = True
+return
+self._execute_request(self.server.system_tests["POST"])
+
+def do_PUT(self):
+self._execute_request(self.server.system_tests["PUT"])
+
+# these overrides just quiet the test output
+# comment them out to help debug:
+def log_request(self, code=None, size=None):
+pass
+
+def log_message(self, format=None, *args):
+pass
+
+def _consume_body(self):
+"""
+Read the entire body off the rfile.  This must be done to allow
+multiple requests on the same socket
+"""
+if self.command == 'HEAD':
+return b''
+
+for key, value in self.headers.items():
+if key.lower() == 'content-length':
+return self.rfile.read(int(value))
+
+if key.lower() == 'transfer-encoding'  \
+   and 'chunked' in value.lower():
+body = b''
+while True:
+header = self.rfile.readline().strip().split(b';')[0]
+hlen = int(header, base=16)
+if hlen > 0:
+data = self.rfile.read(hlen + 2)  # 2 = \r\n
+body += data[:-2]
+else:
+self.rfile.readline()  # discard last \r\n
+break
+return body
+return self.rfile.read()
+
+
+class RequestHandler10(RequestHandler):
+"""
+RequestHandler that forces the server to use HTTP version 1.0 semantics
+"""
+protocol_version = 'HTTP/1.0'
+
+
+class MyHTTPServer(HTTPServer):
+"""
+Adds a switch to the HTTPServer to allow it to exit gracefully
+"""
+
+def __init__(self, addr, handler_cls, testcases):
+self.system_tests = testcases
+self.request_count = 0
+HTTPServer.__init__(self, addr, handler_cls)
+
+def server_close(self):
+try:
+# force immediate close of listening socket
+self.socket.shutdown(socket.SHUT_RDWR)
+except Exception:
+pass
+HTTPServer.server_close(self)
+
+
+class ThreadedTestClient(object):
+"""
+   

[GitHub] [qpid-dispatch] kgiusti commented on a change in pull request #1097: DISPATCH-2029: Added a base class and moved some of the http1 adaptor…

2021-04-07 Thread GitBox


kgiusti commented on a change in pull request #1097:
URL: https://github.com/apache/qpid-dispatch/pull/1097#discussion_r608990009



##
File path: tests/system_tests_http1_base.py
##
@@ -0,0 +1,1187 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+import socket
+import uuid
+from threading import Thread
+
+from time import sleep
+try:
+from http.server import HTTPServer, BaseHTTPRequestHandler
+from http.client import HTTPConnection
+from http.client import HTTPException
+except ImportError:
+from BaseHTTPServer import HTTPServer, BaseHTTPRequestHandler
+from httplib import HTTPConnection, HTTPException
+
+from system_test import TestCase, TIMEOUT, Logger, Qdrouterd
+
+
+class RequestHandler(BaseHTTPRequestHandler):
+"""
+Dispatches requests received by the HTTPServer based on the method
+"""
+protocol_version = 'HTTP/1.1'
+
+def _execute_request(self, tests):
+for req, resp, val in tests:
+if req.target == self.path:
+xhdrs = None
+if "test-echo" in self.headers:
+xhdrs = {"test-echo":
+ self.headers["test-echo"]}
+
+self._consume_body()
+if not isinstance(resp, list):
+resp = [resp]
+for r in resp:
+r.send_response(self, extra_headers=xhdrs)
+self.server.request_count += 1
+return
+self.send_error(404, "Not Found")
+
+def do_GET(self):
+self._execute_request(self.server.system_tests["GET"])
+
+def do_HEAD(self):
+self._execute_request(self.server.system_tests["HEAD"])
+
+def do_POST(self):
+if self.path == "/SHUTDOWN":
+self.send_response(200, "OK")
+self.send_header("Content-Length", "13")
+self.end_headers()
+self.wfile.write(b'Server Closed')
+self.wfile.flush()
+self.close_connection = True
+self.server.server_killed = True
+return
+self._execute_request(self.server.system_tests["POST"])
+
+def do_PUT(self):
+self._execute_request(self.server.system_tests["PUT"])
+
+# these overrides just quiet the test output
+# comment them out to help debug:
+def log_request(self, code=None, size=None):
+pass
+
+def log_message(self, format=None, *args):
+pass
+
+def _consume_body(self):
+"""
+Read the entire body off the rfile.  This must be done to allow
+multiple requests on the same socket
+"""
+if self.command == 'HEAD':
+return b''
+
+for key, value in self.headers.items():
+if key.lower() == 'content-length':
+return self.rfile.read(int(value))
+
+if key.lower() == 'transfer-encoding'  \
+   and 'chunked' in value.lower():
+body = b''
+while True:
+header = self.rfile.readline().strip().split(b';')[0]
+hlen = int(header, base=16)
+if hlen > 0:
+data = self.rfile.read(hlen + 2)  # 2 = \r\n
+body += data[:-2]
+else:
+self.rfile.readline()  # discard last \r\n
+break
+return body
+return self.rfile.read()
+
+
+class RequestHandler10(RequestHandler):
+"""
+RequestHandler that forces the server to use HTTP version 1.0 semantics
+"""
+protocol_version = 'HTTP/1.0'
+
+
+class MyHTTPServer(HTTPServer):
+"""
+Adds a switch to the HTTPServer to allow it to exit gracefully
+"""
+
+def __init__(self, addr, handler_cls, testcases):
+self.system_tests = testcases
+self.request_count = 0
+HTTPServer.__init__(self, addr, handler_cls)
+
+def server_close(self):
+try:
+# force immediate close of listening socket
+self.socket.shutdown(socket.SHUT_RDWR)
+except Exception:
+pass
+HTTPServer.server_close(self)
+
+
+class ThreadedTestClient(object):
+"""
+