You are viewing a plain text version of this content. The canonical link for it is here.
Posted to mod_python-commits@quetz.apache.org by gr...@apache.org on 2006/03/05 02:23:21 UTC

svn commit: r383264 - in /httpd/mod_python/trunk: Doc/appendixc.tex Doc/modpython4.tex lib/python/mod_python/util.py test/htdocs/tests.py test/test.py

Author: grahamd
Date: Sat Mar  4 17:23:20 2006
New Revision: 383264

URL: http://svn.apache.org/viewcvs?rev=383264&view=rev
Log:
Changed util.redirect() to return DONE status instead of OK. (MODPYTHON-140)

Modified:
    httpd/mod_python/trunk/Doc/appendixc.tex
    httpd/mod_python/trunk/Doc/modpython4.tex
    httpd/mod_python/trunk/lib/python/mod_python/util.py
    httpd/mod_python/trunk/test/htdocs/tests.py
    httpd/mod_python/trunk/test/test.py

Modified: httpd/mod_python/trunk/Doc/appendixc.tex
URL: http://svn.apache.org/viewcvs/httpd/mod_python/trunk/Doc/appendixc.tex?rev=383264&r1=383263&r2=383264&view=diff
==============================================================================
--- httpd/mod_python/trunk/Doc/appendixc.tex (original)
+++ httpd/mod_python/trunk/Doc/appendixc.tex Sat Mar  4 17:23:20 2006
@@ -74,6 +74,12 @@
       (\citetitle[http://issues.apache.org/jira/browse/MODPYTHON-134]{MODPYTHON-134})
       Setting \code{PythonDebug} to \code{Off}, wasn't overriding \code{On}
       setting in parent scope.
+    \item
+      (\citetitle[http://issues.apache.org/jira/browse/MODPYTHON-140]{MODPYTHON-140})
+      The \code{util.redirect()} function should be returning server status of
+      \code{apache.DONE} and not \code{apache.OK} otherwise it will not give
+      desired result if used in non content handler phase or where there are
+      stacked content handlers.
   \end{itemize}
 
 \chapter{Changes from Version (3.1.4)\label{app-changes}}

Modified: httpd/mod_python/trunk/Doc/modpython4.tex
URL: http://svn.apache.org/viewcvs/httpd/mod_python/trunk/Doc/modpython4.tex?rev=383264&r1=383263&r2=383264&view=diff
==============================================================================
--- httpd/mod_python/trunk/Doc/modpython4.tex (original)
+++ httpd/mod_python/trunk/Doc/modpython4.tex Sat Mar  4 17:23:20 2006
@@ -1820,10 +1820,11 @@
   If this function is called after the headers have already been sent,
   an \exception{IOError} is raised.
 
-  This function raises \exception{apache.SERVER_RETURN} exception to
-  abandon any further processing of the handle. If you do not want
-  this, you can wrap the call to \function{redirect} in a try/except
-  block catching the \exception{apache.SERVER_RETURN}.
+  This function raises \exception{apache.SERVER_RETURN} exception with
+  a value of \constant{apache.DONE} to ensuring that any later phases or
+  stacked handlers do not run. If you do not want this, you can wrap the
+  call to \function{redirect} in a try/except block catching the
+  \exception{apache.SERVER_RETURN}.
 \end{funcdesc}
 
 \section{\module{Cookie} -- HTTP State Management\label{pyapi-cookie}}

Modified: httpd/mod_python/trunk/lib/python/mod_python/util.py
URL: http://svn.apache.org/viewcvs/httpd/mod_python/trunk/lib/python/mod_python/util.py?rev=383264&r1=383263&r2=383264&view=diff
==============================================================================
--- httpd/mod_python/trunk/lib/python/mod_python/util.py (original)
+++ httpd/mod_python/trunk/lib/python/mod_python/util.py Sat Mar  4 17:23:20 2006
@@ -459,4 +459,4 @@
    else:
        req.write(text)
 
-   raise apache.SERVER_RETURN, apache.OK
+   raise apache.SERVER_RETURN, apache.DONE

Modified: httpd/mod_python/trunk/test/htdocs/tests.py
URL: http://svn.apache.org/viewcvs/httpd/mod_python/trunk/test/htdocs/tests.py?rev=383264&r1=383263&r2=383264&view=diff
==============================================================================
--- httpd/mod_python/trunk/test/htdocs/tests.py (original)
+++ httpd/mod_python/trunk/test/htdocs/tests.py Sat Mar  4 17:23:20 2006
@@ -777,6 +777,19 @@
         req.write('test failed')
         return apache.OK
 
+def util_redirect(req):
+    from mod_python import util
+    if req.main:
+        # Sub request for ErrorDocument.
+        req.write("test failed")
+        return apache.DONE
+    else:
+        if req.phase == "PythonFixupHandler":
+            util.redirect(req,location="/dummy",text="test ok")
+        else:
+            req.write('test failed')
+            return apache.OK
+
 def req_server_get_config(req):
 
     if req.server.get_config().get("PythonDebug","0") != "1" or \

Modified: httpd/mod_python/trunk/test/test.py
URL: http://svn.apache.org/viewcvs/httpd/mod_python/trunk/test/test.py?rev=383264&r1=383263&r2=383264&view=diff
==============================================================================
--- httpd/mod_python/trunk/test/test.py (original)
+++ httpd/mod_python/trunk/test/test.py Sat Mar  4 17:23:20 2006
@@ -1008,6 +1008,38 @@
         if (rsp != "test ok"):
             self.fail(`rsp`)
 
+    def test_util_redirect_conf(self):
+
+        c = VirtualHost("*",
+                        ServerName("test_util_redirect"),
+                        DocumentRoot(DOCUMENT_ROOT),
+                        Directory(DOCUMENT_ROOT,
+                                  PythonFixupHandler("tests::util_redirect"),
+                                  PythonHandler("tests::util_redirect"),
+                                  PythonDebug("On")))
+        return str(c)
+
+    def test_util_redirect(self):
+
+        print "\n  * Testing util.redirect()"
+        
+        conn = httplib.HTTPConnection("127.0.0.1:%s" % PORT)
+        conn.putrequest("GET", "/", skip_host=1)
+        conn.putheader("Host", "%s:%s" % ("test_util_redirect", PORT))
+        conn.endheaders()
+        response = conn.getresponse()
+        rsp = response.read()
+        conn.close()
+
+        if response.status != 302:
+            self.fail('did not receive 302 status response')
+
+        if response.getheader("location", None) != "/dummy":
+            self.fail('did not receive correct location for redirection')
+        
+        if rsp != "test ok":
+            self.fail(`rsp`)
+
     def test_req_server_get_config_conf(self):
 
         c = VirtualHost("*",
@@ -2193,6 +2225,7 @@
         perRequestSuite.addTest(PerRequestTestCase("test_req_sendfile2"))
         perRequestSuite.addTest(PerRequestTestCase("test_req_sendfile3"))
         perRequestSuite.addTest(PerRequestTestCase("test_req_handler"))
+        perRequestSuite.addTest(PerRequestTestCase("test_util_redirect"))
         perRequestSuite.addTest(PerRequestTestCase("test_req_server_get_config"))
         perRequestSuite.addTest(PerRequestTestCase("test_req_server_get_options"))
         perRequestSuite.addTest(PerRequestTestCase("test_fileupload"))