Commits

Robert Brewer committed 3cfe780

New Engine.response_class attribute (which allows a new -null switch for benchmark.py, to show how much of the request is spent in the HTTP server as opposed to the Request object).

  • Participants
  • Parent commits ba343ad

Comments (0)

Files changed (3)

File cherrypy/_cpengine.py

     """The application server engine, connecting HTTP servers to Requests."""
     
     request_class = _cphttptools.Request
+    response_class = _cphttptools.Response
     
     def __init__(self):
         self.state = STOPPED
         r = self.request_class(clientAddress[0], clientAddress[1],
                                remoteHost, scheme)
         cherrypy.serving.request = r
-        cherrypy.serving.response = _cphttptools.Response()
+        cherrypy.serving.response = self.response_class()
         return r
 

File cherrypy/test/bench_mp.conf

 
 <Location />
     SetHandler python-program
-    PythonFixupHandler cherrypy.test.benchmark::startup
+    
+    <IfDefine !nullreq>
+        PythonFixupHandler cherrypy.test.benchmark::startup
+    </IfDefine>
+    <IfDefine nullreq>
+        PythonFixupHandler cherrypy.test.benchmark::startup_null
+    </IfDefine>
+    
     PythonHandler modpython_gateway::handler
     PythonOption application cherrypy._cpwsgi::wsgiApp
     PythonDebug On

File cherrypy/test/benchmark.py

 import traceback
 
 import cherrypy
+from cherrypy.lib import httptools
 
 
 MOUNT_POINT = "/cpbench/users/rdelon/apps/blog"
     print_chart(size_chart())
 
 
+class NullRequest:
+    """A null HTTP request class, returning 204 and an empty body."""
+    
+    def __init__(self, remoteAddr, remotePort, remoteHost, scheme="http"):
+        pass
+    
+    def close(self):
+        pass
+    
+    def run(self, requestLine, headers, rfile):
+        cherrypy.response.status = "204 No Content"
+        cherrypy.response.header_list = [("Content-Type", 'text/html'),
+                                         ("Server", "Null CherryPy"),
+                                         ("Date", httptools.HTTPDate()),
+                                         ("Content-Length", "0"),
+                                         ]
+        cherrypy.response.body = [""]
+        return cherrypy.response
+
+
+class NullResponse:
+    pass
+
+
 started = False
 def startup(req=None):
     """Start the CherryPy app server in 'serverless' mode (for WSGI)."""
         cherrypy.server.start(init_only=True, server_class=None)
     return 0 # apache.OK
 
+def startup_null(req=None):
+    """Start the CherryPy app server in NULL 'serverless' mode (for WSGI)."""
+    global started
+    if not started:
+        started = True
+        cherrypy.server.request_class = NullRequest
+        cherrypy.server.response_class = NullResponse
+        cherrypy.server.start(init_only=True, server_class=None)
+    return 0 # apache.OK
+
 
 if __name__ == '__main__':
     if "-notests" in sys.argv:
     if "-modpython" in sys.argv:
         try:
             mpconf = os.path.join(curdir, "bench_mp.conf")
-            read_process("apache", "-k start -f %s" % mpconf)
+            if "-null" in sys.argv:
+                # Pass the null option through Apache
+                read_process("apache", "-k start -D nullreq -f %s" % mpconf)
+            else:
+                read_process("apache", "-k start -f %s" % mpconf)
             run()
         finally:
             os.popen("apache -k stop")
     else:
+        if "-null" in sys.argv:
+            cherrypy.server.request_class = NullRequest
+            cherrypy.server.response_class = NullResponse
+        
         # This will block
         cherrypy.server.start_with_callback(run)