[Zope-Checkins] CVS: Zope3/lib/python/Zope/Publisher/HTTP - HTTPRequest.py:1.1.2.24.2.1 HTTPResponse.py:1.1.2.16.2.1

Shane Hathaway shane@cvs.zope.org
Thu, 11 Apr 2002 12:34:46 -0400


Update of /cvs-repository/Zope3/lib/python/Zope/Publisher/HTTP
In directory cvs.zope.org:/tmp/cvs-serv13902/HTTP

Modified Files:
      Tag: Zope3-Server-Branch
	HTTPRequest.py HTTPResponse.py 
Log Message:
- Fixed status code handling.  For HTTP, default to a special 599, which
means nothing set the status code.  Added an internalError() call, which
should tell the client that the server failed to handle an exception.

- Fixed the retry mechanism.  Because the status code check was disabled
in testHTTPServer, no one knew that retry wasn't working at all.
(tsk, tsk!)  Had to add another argument to request constructors.


=== Zope3/lib/python/Zope/Publisher/HTTP/HTTPRequest.py 1.1.2.24 => 1.1.2.24.2.1 ===
         '_app_server',    # The server path of the application url
         '_orig_env',      # The original environment
-        '_endswithslash'  # Does the given path end with /
+        '_endswithslash', # Does the given path end with /
         )
 
     retry_max_count = 3    # How many times we're willing to retry
 
-    def __init__(self, body_instream, outstream, environ):
+    def __init__(self, body_instream, outstream, environ, response=None):
 
-        super(HTTPRequest, self).__init__(body_instream, outstream, environ)
+        super(HTTPRequest, self).__init__(
+            body_instream, outstream, environ, response)
 
         self._orig_env = environ
         environ = sane_environment(environ)
@@ -293,22 +294,27 @@
 
     def supportsRetry(self):
         'See Zope.Publisher.IPublisherRequest.IPublisherRequest'
-        if self._retry_count < self.retry_max_count:
+        count = getattr(self, '_retry_count', 0)
+        if count < self.retry_max_count:
             if STAGGER_RETRIES:
-                time.sleep(whrandom.uniform(0, 2**(self.retry_count)))
+                time.sleep(random.uniform(0, 2**(count)))
             return 1
 
 
     def retry(self):
         'See Zope.Publisher.IPublisherRequest.IPublisherRequest'
-        self.retry_count = self.retry_count + 1
-        self.body_instream.seek(0)
+        count = getattr(self, '_retry_count', 0)
+        self._retry_count = count + 1
+        self._body_instream.seek(0)
+        new_response = self.getResponse().retry()
         request = self.__class__(
-            body_instream = self._body_instream,
-            outstream = self.getResponse().getOutputStream(),
-            environ = self._orig_env
+            body_instream=self._body_instream,
+            outstream=None,
+            environ=self._orig_env,
+            response=new_response,
             )
-        request.retry_count = self.retry_count
+        request.setPublication(self.getPublication())
+        request._retry_count = self._retry_count
         return request
 
 


=== Zope3/lib/python/Zope/Publisher/HTTP/HTTPResponse.py 1.1.2.16 => 1.1.2.16.2.1 ===
         '_wrote_headers',
         '_streaming',
-        '_status',      # The response status (usually an integer)
-        '_reason'       # The reason that goes with the status
+        '_status',              # The response status (usually an integer)
+        '_reason',              # The reason that goes with the status
+        '_status_set',          # Boolean: status explicitly set
         )
 
 
@@ -121,8 +122,9 @@
         self._accumulated_headers = []
         self._wrote_headers = 0
         self._streaming = 0
-        self._status = 200
-        self._reason = 'Ok'
+        self._status = 599
+        self._reason = 'No status set'
+        self._status_set = 0
 
 
     def setHeaderOutput(self, header_output):
@@ -143,7 +145,7 @@
             if status_codes.has_key(status):
                 status = status_codes[status]
             else:
-                status=500
+                status = 500
         self._status = status
 
         if reason is None:
@@ -154,6 +156,7 @@
             else:
                 reason = 'Unknown'
         self._reason = reason
+        self._status_set = 1
 
 
     def getStatus(self):
@@ -261,6 +264,11 @@
     ######################################
     # from: Zope.Publisher.IPublisherResponse.IPublisherResponse
 
+    def setBody(self, body):
+        self._body = body
+        if not self._status_set:
+            self.setStatus(200)
+
     def handleException(self, exc_info):
         """
         Calls self.setBody() with an error response.
@@ -283,6 +291,11 @@
         self.setBody(body)
 
 
+    def internalError(self):
+        'See Zope.Publisher.IPublisherResponse.IPublisherResponse'
+        self.setStatus(500, "The engines can't take any more, Jim!")
+
+
     def _html(self, title, content):
         t = escape(title)
         return (
@@ -292,9 +305,6 @@
             "</body></html>\n" %
             (t, t, content)
             )
-
-
-
 
 
     def retry(self):