Re: Extreme bafflement

Matt Patterson <[email protected]>
Newsgroups gmane.comp.web.quixote.user
Message-ID <[email protected]>
On 4 Oct 2005, at 18:17, Matt Patterson wrote:

>>>> Is the scgi process stuck in HTTPRequest.process_inputs() during  
>>>> the delay?
>>>> Is it that the read() call in the scgi process is blocked,  
>>>> waiting for
>>>> the final bytes of the request, which never come (due to a bug  
>>>> somewhere)?
>>>
>>> I don't know. I'm going to dig out pdb and find out...
>>
>> If it were me, I'd just put prints with timestamps around the read 
>> () calls.
>> If they blow by without much delay, you'll know right away that  
>> this theory is
>> false.
>
> Cool. Thanks David!

[snip]

> I've altered my code to check the content-type before it does  
> anything daft now, but is there any chance of a method on  
> HTTPRequest to retrieve the message body (maybe that only returns  
> in when request.form hasn't been populated)?

I've pressed ahead a bit with this, and the patch below is to allow  
you to be able to subclass http_request.HTTPRequest and have that new  
class be used by the publisher.

It works by using a request_class keyword argument in  
Publisher.__init__ and providing a new Publisher.create_request 
(stdin, environ) method, which returns a request object (instance of  
request_class).

The patch also modifies all the server connection modules in server/.

Basically, code which doesn't subclass the Publisher and just uses  
one of the server connection modules in server/ should run unaltered  
(my SCGI stuff does, haven't tested the other stuff).

Anything that subclasses Publisher will be fine if calls the  
Publisher __init__, and doesn't define its own create_request()  
method or _request_class instance var.

Being able to subclass and use my own Request pretty much allows me  
to solve all my problems, which is cool.

Matt

-- 
   Matt Patterson | Design & Code
   <matt at emdash co uk> | http://www.emdash.co.uk/
   <matt at reprocessed org> | http://www.reprocessed.org/

_______________________________________________
Quixote-users mailing list
[email protected]
http://mail.mems-exchange.org/mailman/listinfo/quixote-users
q_request_mods.patch (application/octet-stream, 5.9 KB)
diff -ru Quixote-2.3/publish.py Quixote-2.3_request_mod/publish.py
--- Quixote-2.3/publish.py	2005-09-22 15:18:03.000000000 +0100
+++ Quixote-2.3_request_mod/publish.py	2005-10-24 15:55:02.000000000 +0100
@@ -13,6 +13,7 @@
 from quixote import util
 from quixote.config import Config
 from quixote.http_response import HTTPResponse
+from quixote.http_request import HTTPRequest
 from quixote.logger import DefaultLogger
 
 # Error message to dispay when DISPLAY_EXCEPTIONS in config file is not
@@ -71,7 +72,7 @@
     """
 
     def __init__(self, root_directory, logger=None, session_manager=None,
-                 config=None, **kwargs):
+                 config=None, request_class = HTTPRequest, **kwargs):
         global _publisher
         if config is None:
             self.config = Config(**kwargs)
@@ -102,6 +103,7 @@
                 root_directory)
         self.root_directory = root_directory
         self._request = None
+        self._request_class = request_class
 
     def set_session_manager(self, session_manager):
         self.session_manager = session_manager
@@ -109,6 +111,11 @@
     def log(self, msg):
         self.logger.log(msg)
 
+    def create_request(self, stdin, environ):
+        """Create a request object
+        """
+        return self._request_class(stdin, environ)
+
     def parse_request(self, request):
         """Parse the request information waiting in 'request'.
         """
diff -ru Quixote-2.3/server/cgi_server.py Quixote-2.3_request_mod/server/cgi_server.py
--- Quixote-2.3/server/cgi_server.py	2004-11-10 22:37:39.000000000 +0000
+++ Quixote-2.3_request_mod/server/cgi_server.py	2005-10-24 16:01:31.000000000 +0100
@@ -14,7 +14,7 @@
         msvcrt.setmode(sys.__stdin__.fileno(), os.O_BINARY)
         msvcrt.setmode(sys.__stdout__.fileno(), os.O_BINARY)
     publisher = create_publisher()
-    request = HTTPRequest(sys.__stdin__, os.environ)
+    request = publisher.create_request(sys.__stdin__, os.environ)
     response = publisher.process_request(request)
     try:
         response.write(sys.__stdout__)
diff -ru Quixote-2.3/server/fastcgi_server.py Quixote-2.3_request_mod/server/fastcgi_server.py
--- Quixote-2.3/server/fastcgi_server.py	2004-10-28 23:52:11.000000000 +0100
+++ Quixote-2.3_request_mod/server/fastcgi_server.py	2005-10-24 16:01:06.000000000 +0100
@@ -14,7 +14,7 @@
     publisher = create_publisher()
     while _fcgi.isFCGI():
         f = _fcgi.FCGI()
-        request = HTTPRequest(f.inp, f.env)
+        request = publisher.create_request(f.inp, f.env)
         response = publisher.process_request(request)
         try:
             response.write(f.out)
diff -ru Quixote-2.3/server/medusa_server.py Quixote-2.3_request_mod/server/medusa_server.py
--- Quixote-2.3/server/medusa_server.py	2004-11-11 21:13:42.000000000 +0000
+++ Quixote-2.3_request_mod/server/medusa_server.py	2005-10-24 16:00:28.000000000 +0100
@@ -86,7 +86,7 @@
             environ[envname] = header
 
         stdin = StringIO(data)
-        qrequest = HTTPRequest(stdin, environ)
+        qrequest = self.publisher.create_request(stdin, environ)
         qresponse = self.publisher.process_request(qrequest)
 
         # Copy headers from Quixote's HTTP response
diff -ru Quixote-2.3/server/mod_python_handler.py Quixote-2.3_request_mod/server/mod_python_handler.py
--- Quixote-2.3/server/mod_python_handler.py	2005-01-19 14:26:25.000000000 +0000
+++ Quixote-2.3_request_mod/server/mod_python_handler.py	2005-10-24 15:59:42.000000000 +0100
@@ -81,8 +81,7 @@
 name2publisher = {}
 
 def run(publisher, req):
-    from quixote.http_request import HTTPRequest
-    request = HTTPRequest(apache.CGIStdin(req), apache.build_cgi_env(req))
+    request = publisher.create_request(apache.CGIStdin(req), apache.build_cgi_env(req))
     response = publisher.process_request(request)
     try:
         response.write(apache.CGIStdout(req))
diff -ru Quixote-2.3/server/scgi_server.py Quixote-2.3_request_mod/server/scgi_server.py
--- Quixote-2.3/server/scgi_server.py	2005-08-10 21:33:41.000000000 +0100
+++ Quixote-2.3_request_mod/server/scgi_server.py	2005-10-24 15:59:00.000000000 +0100
@@ -28,7 +28,7 @@
             env['SCRIPT_NAME'] = prefix
             env['PATH_INFO'] = path[len(prefix):] + env.get('PATH_INFO', '')
 
-        request = HTTPRequest(input, env)
+        request = self.publisher.create_request(input, env)
         response = self.publisher.process_request(request)
         try:
             response.write(output)
diff -ru Quixote-2.3/server/simple_server.py Quixote-2.3_request_mod/server/simple_server.py
--- Quixote-2.3/server/simple_server.py	2005-09-06 17:58:49.000000000 +0100
+++ Quixote-2.3_request_mod/server/simple_server.py	2005-10-24 15:58:16.000000000 +0100
@@ -53,8 +53,9 @@
         return env
 
     def process(self, env, include_body=True):
-        request = HTTPRequest(self.rfile, env)
-        response = get_publisher().process_request(request)
+        publisher = get_publisher()
+        response = publisher.process_request(
+            publisher.create_request(self.rfile, env))
         try:
             self.send_response(response.get_status_code(),
                                response.get_reason_phrase())
diff -ru Quixote-2.3/server/twisted_server.py Quixote-2.3_request_mod/server/twisted_server.py
--- Quixote-2.3/server/twisted_server.py	2004-12-08 20:46:16.000000000 +0000
+++ Quixote-2.3_request_mod/server/twisted_server.py	2005-10-24 15:56:06.000000000 +0100
@@ -30,7 +30,7 @@
         # this seek is important, it doesn't work without it (it doesn't
         # matter for GETs, but POSTs will not work properly without it.)
         self.content.seek(0, 0)
-        qxrequest = HTTPRequest(self.content, environ)
+        qxrequest = self.channel.factory.publisher.create_request(self.content, environ)
         qxresponse = self.channel.factory.publisher.process_request(qxrequest)
         self.setResponseCode(qxresponse.status_code)
         for name, value in qxresponse.generate_headers():
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.