diff --git a/src/main/java/org/tuckey/web/filters/urlrewrite/NormalRewrittenUrl.java b/src/main/java/org/tuckey/web/filters/urlrewrite/NormalRewrittenUrl.java index 60250eef..62325f90 100644 --- a/src/main/java/org/tuckey/web/filters/urlrewrite/NormalRewrittenUrl.java +++ b/src/main/java/org/tuckey/web/filters/urlrewrite/NormalRewrittenUrl.java @@ -60,6 +60,8 @@ public class NormalRewrittenUrl implements RewrittenUrl { private boolean redirect = false; private boolean permanentRedirect = false; private boolean temporaryRedirect = false; + private boolean permanentRedirect308 = false; + private boolean temporaryRedirect307 = false; private boolean preInclude = false; private boolean postInclude = false; private boolean proxy = false; @@ -72,7 +74,7 @@ public class NormalRewrittenUrl implements RewrittenUrl { private ServletContext targetContext = null; /** - * Holds information about the rewirtten url. + * Holds information about the rewritten url. * * @param ruleExecutionOutput the url to rewrite to */ @@ -135,6 +137,22 @@ public boolean isTemporaryRedirect() { return temporaryRedirect; } + public void set308PermanentRedirect(boolean permanentRedirect308) { + this.permanentRedirect308 = permanentRedirect308; + } + + public boolean is308PermanentRedirect() { + return permanentRedirect308; + } + + public void set307TemporaryRedirect(boolean temporaryRedirect307) { + this.temporaryRedirect307 = temporaryRedirect307; + } + + public boolean is307TemporaryRedirect() { + return temporaryRedirect307; + } + public void setEncode(boolean b) { encode = b; } @@ -272,6 +290,34 @@ public boolean doRewrite(final HttpServletRequest hsRequest, } requestRewritten = true; + } else if (is307TemporaryRedirect()) { + if (hsResponse.isCommitted()) { + log.error("response is committed cannot temporary redirect (307) to " + target + + " (check you haven't done anything to the response (ie, written to it) before here)"); + } else { + if (isEncode()) { + target = hsResponse.encodeRedirectURL(target); + } + hsResponse.setStatus(HttpServletResponse.SC_TEMPORARY_REDIRECT); + hsResponse.setHeader("Location", target); + if (log.isDebugEnabled()) log.debug("temporarily redirected (with response 307) to " + target); + } + requestRewritten = true; + + } else if (is308PermanentRedirect()) { + if (hsResponse.isCommitted()) { + log.error("response is committed cannot permanent redirect (308) to " + target + + " (check you haven't done anything to the response (ie, written to it) before here)"); + } else { + if (isEncode()) { + target = hsResponse.encodeRedirectURL(target); + } + hsResponse.setStatus(308); + hsResponse.setHeader("Location", target); + if (log.isDebugEnabled()) log.debug("permanently redirected (with response 308) to " + target); + } + requestRewritten = true; + } else if (isProxy()) { if (hsResponse.isCommitted()) { log.error("response is committed. cannot proxy " + target + ". Check that you havn't written to the response before."); diff --git a/src/main/java/org/tuckey/web/filters/urlrewrite/NormalRule.java b/src/main/java/org/tuckey/web/filters/urlrewrite/NormalRule.java index 0252ca4f..80f2e0d3 100644 --- a/src/main/java/org/tuckey/web/filters/urlrewrite/NormalRule.java +++ b/src/main/java/org/tuckey/web/filters/urlrewrite/NormalRule.java @@ -65,6 +65,8 @@ public class NormalRule extends RuleBase implements Rule { public static final short TO_TYPE_PRE_INCLUDE = 4; public static final short TO_TYPE_POST_INCLUDE = 5; public static final short TO_TYPE_PROXY = 6; + public static final short TO_TYPE_307_TEMPORARY_REDIRECT = 7; + public static final short TO_TYPE_308_PERMANENT_REDIRECT = 8; private boolean dropCookies = true; private boolean encodeToUrl = false; @@ -164,6 +166,10 @@ public void setToType(final String toTypeStr) { toType = TO_TYPE_PERMANENT_REDIRECT; } else if ("temporary-redirect".equals(toTypeStr)) { toType = TO_TYPE_TEMPORARY_REDIRECT; + } else if ("308-permanent-redirect".equals(toTypeStr)) { + toType = TO_TYPE_308_PERMANENT_REDIRECT; + } else if ("307-temporary-redirect".equals(toTypeStr)) { + toType = TO_TYPE_307_TEMPORARY_REDIRECT; } else if ("pre-include".equals(toTypeStr)) { toType = TO_TYPE_PRE_INCLUDE; } else if ("post-include".equals(toTypeStr)) { @@ -187,6 +193,8 @@ public String getToType() { if (toType == TO_TYPE_REDIRECT) return "redirect"; if (toType == TO_TYPE_PERMANENT_REDIRECT) return "permanent-redirect"; if (toType == TO_TYPE_TEMPORARY_REDIRECT) return "temporary-redirect"; + if (toType == TO_TYPE_308_PERMANENT_REDIRECT) return "permanent-redirect-308"; + if (toType == TO_TYPE_307_TEMPORARY_REDIRECT) return "temporary-redirect-307"; if (toType == TO_TYPE_PRE_INCLUDE) return "pre-include"; if (toType == TO_TYPE_POST_INCLUDE) return "post-include"; if (toType == TO_TYPE_PROXY) return "proxy"; diff --git a/src/main/java/org/tuckey/web/filters/urlrewrite/RuleExecutionOutput.java b/src/main/java/org/tuckey/web/filters/urlrewrite/RuleExecutionOutput.java index 11e2061e..cd7be468 100644 --- a/src/main/java/org/tuckey/web/filters/urlrewrite/RuleExecutionOutput.java +++ b/src/main/java/org/tuckey/web/filters/urlrewrite/RuleExecutionOutput.java @@ -84,6 +84,18 @@ public static RewrittenUrl getRewritenUrl(short toType, boolean encodeToUrl, Rul } rewrittenRequest.setTemporaryRedirect(true); + } else if (toType == NormalRule.TO_TYPE_308_PERMANENT_REDIRECT) { + if (log.isDebugEnabled()) { + log.debug("needs to be permanently redirected (with response code 308) to " + toUrl); + } + rewrittenRequest.set308PermanentRedirect(true); + + } else if (toType == NormalRule.TO_TYPE_307_TEMPORARY_REDIRECT) { + if (log.isDebugEnabled()) { + log.debug("needs to be temporarily redirected (with response code 307) to " + toUrl); + } + rewrittenRequest.set307TemporaryRedirect(true); + } else if (toType == NormalRule.TO_TYPE_PRE_INCLUDE) { if (log.isDebugEnabled()) { log.debug(toUrl + " needs to be pre included");