]> git.ipfire.org Git - thirdparty/tornado.git/commitdiff
Make HTTPServer Configurable.
authorBen Darnell <ben@bendarnell.com>
Sun, 8 Mar 2015 23:05:28 +0000 (19:05 -0400)
committerBen Darnell <ben@bendarnell.com>
Sun, 8 Mar 2015 23:05:28 +0000 (19:05 -0400)
Relax some overly-specific tests.

tornado/httpserver.py
tornado/test/httpserver_test.py
tornado/test/runtests.py

index 13a6e92facff4c0f2cf9734948fbee700f4a99d0..226f966a32beea099ea4e2a78b7ce58d1bbe712b 100644 (file)
@@ -37,9 +37,11 @@ from tornado import httputil
 from tornado import iostream
 from tornado import netutil
 from tornado.tcpserver import TCPServer
+from tornado.util import Configurable
 
 
-class HTTPServer(TCPServer, httputil.HTTPServerConnectionDelegate):
+class HTTPServer(TCPServer, Configurable,
+                 httputil.HTTPServerConnectionDelegate):
     r"""A non-blocking, single-threaded HTTP server.
 
     A server is defined by a subclass of `.HTTPServerConnectionDelegate`,
@@ -120,12 +122,20 @@ class HTTPServer(TCPServer, httputil.HTTPServerConnectionDelegate):
        two arguments ``(server_conn, request_conn)`` (in accordance with the
        documentation) instead of one ``(request_conn)``.
     """
-    def __init__(self, request_callback, no_keep_alive=False, io_loop=None,
-                 xheaders=False, ssl_options=None, protocol=None,
-                 decompress_request=False,
-                 chunk_size=None, max_header_size=None,
-                 idle_connection_timeout=None, body_timeout=None,
-                 max_body_size=None, max_buffer_size=None):
+    def __init__(self, *args, **kwargs):
+        # Ignore args to __init__; real initialization belongs in
+        # initialize since we're Configurable. (there's something
+        # weird in initialization order between this class,
+        # Configurable, and TCPServer so we can't leave __init__ out
+        # completely)
+        pass
+
+    def initialize(self, request_callback, no_keep_alive=False, io_loop=None,
+                   xheaders=False, ssl_options=None, protocol=None,
+                   decompress_request=False,
+                   chunk_size=None, max_header_size=None,
+                   idle_connection_timeout=None, body_timeout=None,
+                   max_body_size=None, max_buffer_size=None):
         self.request_callback = request_callback
         self.no_keep_alive = no_keep_alive
         self.xheaders = xheaders
@@ -142,6 +152,14 @@ class HTTPServer(TCPServer, httputil.HTTPServerConnectionDelegate):
                            read_chunk_size=chunk_size)
         self._connections = set()
 
+    @classmethod
+    def configurable_base(cls):
+        return HTTPServer
+
+    @classmethod
+    def configurable_default(cls):
+        return HTTPServer
+
     @gen.coroutine
     def close_all_connections(self):
         while self._connections:
index 62ef6ca3d5f2373f1ab90dcd11e7e1c0bc7e5c87..c1ba831cf1e343b961eab5edbae48b0ee8b3da6d 100644 (file)
@@ -162,19 +162,22 @@ class BadSSLOptionsTest(unittest.TestCase):
         application = Application()
         module_dir = os.path.dirname(__file__)
         existing_certificate = os.path.join(module_dir, 'test.crt')
+        existing_key = os.path.join(module_dir, 'test.key')
 
-        self.assertRaises(ValueError, HTTPServer, application, ssl_options={
-                          "certfile": "/__mising__.crt",
+        self.assertRaises((ValueError, IOError),
+                          HTTPServer, application, ssl_options={
+                              "certfile": "/__mising__.crt",
                           })
-        self.assertRaises(ValueError, HTTPServer, application, ssl_options={
-                          "certfile": existing_certificate,
-                          "keyfile": "/__missing__.key"
+        self.assertRaises((ValueError, IOError),
+                          HTTPServer, application, ssl_options={
+                              "certfile": existing_certificate,
+                              "keyfile": "/__missing__.key"
                           })
 
         # This actually works because both files exist
         HTTPServer(application, ssl_options={
                    "certfile": existing_certificate,
-                   "keyfile": existing_certificate
+                   "keyfile": existing_key,
                    })
 
 
index 20133d4e2921f6a8654de8dfd74e3fbf87b98c70..cb9969d3c34162eab3e95462478108ec0feab049 100644 (file)
@@ -8,6 +8,7 @@ import operator
 import textwrap
 import sys
 from tornado.httpclient import AsyncHTTPClient
+from tornado.httpserver import HTTPServer
 from tornado.ioloop import IOLoop
 from tornado.netutil import Resolver
 from tornado.options import define, options, add_parse_callback
@@ -123,6 +124,8 @@ def main():
     define('httpclient', type=str, default=None,
            callback=lambda s: AsyncHTTPClient.configure(
                s, defaults=dict(allow_ipv6=False)))
+    define('httpserver', type=str, default=None,
+           callback=HTTPServer.configure)
     define('ioloop', type=str, default=None)
     define('ioloop_time_monotonic', default=False)
     define('resolver', type=str, default=None,