r9499 - helma/helma/trunk/src/helma/servlet

[email protected]
Newsgroups gmane.comp.java.helma.cvs
Message-ID <[email protected]>
Author: hannes
Date: 2009-02-02 16:35:00 +0100 (Mon, 02 Feb 2009)
New Revision: 9499

Modified:
   helma/helma/trunk/src/helma/servlet/AbstractServletClient.java
Log:
Allow applications to explicitly set the HTTP status code with res.redirect().

Details at http://dev.helma.org/trac/helma/changeset/9499

Modified: helma/helma/trunk/src/helma/servlet/AbstractServletClient.java
===================================================================
--- helma/helma/trunk/src/helma/servlet/AbstractServletClient.java	2009-01-30 11:00:18 UTC (rev 9498)
+++ helma/helma/trunk/src/helma/servlet/AbstractServletClient.java	2009-02-02 15:35:00 UTC (rev 9499)
@@ -311,7 +311,7 @@
         }
 
         if (hopres.getRedirect() != null) {
-            sendRedirect(req, res, hopres.getRedirect());
+            sendRedirect(req, res, hopres.getRedirect(), hopres.getStatus());
         } else if (hopres.getNotModified()) {
             res.setStatus(HttpServletResponse.SC_NOT_MODIFIED);
         } else {
@@ -383,7 +383,7 @@
         }
     }
 
-    void sendRedirect(HttpServletRequest req, HttpServletResponse res, String url) {
+    void sendRedirect(HttpServletRequest req, HttpServletResponse res, String url, int status) {
         String location = url;
 
         if (url.indexOf("://") == -1) {
@@ -421,8 +421,11 @@
             location = loc.toString();
         }
 
-        // send status code 303 for HTTP 1.1, 302 otherwise
-        if (isOneDotOne(req.getProtocol())) {
+        // if status code was explicitly set use that, or use 303 for HTTP 1.1,
+        // 302 for earlier protocol versions
+        if (status >= 301 && status <= 303) {
+            res.setStatus(status);
+        } else if (isOneDotOne(req.getProtocol())) {
             res.setStatus(HttpServletResponse.SC_SEE_OTHER);
         } else {
             res.setStatus(HttpServletResponse.SC_MOVED_TEMPORARILY);
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.