Polishing
This commit is contained in:
@@ -93,7 +93,7 @@ public class ForwardedHeaderFilter extends OncePerRequestFilter {
|
||||
/**
|
||||
* Enables mode in which any "Forwarded" or "X-Forwarded-*" headers are
|
||||
* removed only and the information in them ignored.
|
||||
* @param removeOnly whether to discard and ingore forwarded headers
|
||||
* @param removeOnly whether to discard and ignore forwarded headers
|
||||
* @since 4.3.9
|
||||
*/
|
||||
public void setRemoveOnly(boolean removeOnly) {
|
||||
@@ -109,7 +109,7 @@ public class ForwardedHeaderFilter extends OncePerRequestFilter {
|
||||
* to turn relative into absolute URLs since (which Servlet containers are
|
||||
* also required to do) also taking forwarded headers into consideration.
|
||||
* @param relativeRedirects whether to use relative redirects
|
||||
* @since 5.0
|
||||
* @since 4.3.10
|
||||
*/
|
||||
public void setRelativeRedirects(boolean relativeRedirects) {
|
||||
this.relativeRedirects = relativeRedirects;
|
||||
@@ -148,9 +148,9 @@ public class ForwardedHeaderFilter extends OncePerRequestFilter {
|
||||
}
|
||||
else {
|
||||
HttpServletRequest theRequest = new ForwardedHeaderExtractingRequest(request, this.pathHelper);
|
||||
HttpServletResponse theResponse = this.relativeRedirects ?
|
||||
HttpServletResponse theResponse = (this.relativeRedirects ?
|
||||
RelativeRedirectResponseWrapper.wrapIfNecessary(response, HttpStatus.SEE_OTHER) :
|
||||
new ForwardedHeaderExtractingResponse(response, theRequest);
|
||||
new ForwardedHeaderExtractingResponse(response, theRequest));
|
||||
filterChain.doFilter(theRequest, theResponse);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,14 +16,14 @@
|
||||
|
||||
package org.springframework.web.filter;
|
||||
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
import java.io.IOException;
|
||||
import javax.servlet.FilterChain;
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.IOException;
|
||||
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
/**
|
||||
* Overrides {@link HttpServletResponse#sendRedirect(String)} and handles it by
|
||||
@@ -32,12 +32,12 @@ import java.io.IOException;
|
||||
* recommendation in <a href="https://tools.ietf.org/html/rfc7231#section-7.1.2">
|
||||
* RFC 7231 Section 7.1.2</a>.
|
||||
*
|
||||
* <p><strong>Note:</strong> while relative redirects are more efficient they
|
||||
* <p><strong>Note:</strong> While relative redirects are more efficient they
|
||||
* may not work with reverse proxies under some configurations.
|
||||
*
|
||||
* @author Rob Winch
|
||||
* @author Rossen Stoyanchev
|
||||
* @since 5.0
|
||||
* @since 4.3.10
|
||||
*/
|
||||
public class RelativeRedirectFilter extends OncePerRequestFilter {
|
||||
|
||||
@@ -50,8 +50,8 @@ public class RelativeRedirectFilter extends OncePerRequestFilter {
|
||||
* @param status the 3xx redirect status to use
|
||||
*/
|
||||
public void setRedirectStatus(HttpStatus status) {
|
||||
Assert.notNull(status, "HttpStatus is required");
|
||||
Assert.isTrue(status.is3xxRedirection(), "Not a redirect status: " + status);
|
||||
Assert.notNull(status, "Property 'redirectStatus' is required");
|
||||
Assert.isTrue(status.is3xxRedirection(), "Not a redirect status code");
|
||||
this.redirectStatus = status;
|
||||
}
|
||||
|
||||
|
||||
@@ -29,7 +29,7 @@ import org.springframework.util.Assert;
|
||||
* {@link RelativeRedirectFilter} also shared with {@link ForwardedHeaderFilter}.
|
||||
*
|
||||
* @author Rossen Stoyanchev
|
||||
* @since 5.0
|
||||
* @since 4.3.10
|
||||
*/
|
||||
class RelativeRedirectResponseWrapper extends HttpServletResponseWrapper {
|
||||
|
||||
@@ -38,7 +38,7 @@ class RelativeRedirectResponseWrapper extends HttpServletResponseWrapper {
|
||||
|
||||
private RelativeRedirectResponseWrapper(HttpServletResponse response, HttpStatus redirectStatus) {
|
||||
super(response);
|
||||
Assert.notNull(redirectStatus, "'redirectStatus' is required.");
|
||||
Assert.notNull(redirectStatus, "'redirectStatus' is required");
|
||||
this.redirectStatus = redirectStatus;
|
||||
}
|
||||
|
||||
@@ -53,8 +53,7 @@ class RelativeRedirectResponseWrapper extends HttpServletResponseWrapper {
|
||||
public static HttpServletResponse wrapIfNecessary(HttpServletResponse response,
|
||||
HttpStatus redirectStatus) {
|
||||
|
||||
return hasWrapper(response) ? response :
|
||||
new RelativeRedirectResponseWrapper(response, redirectStatus);
|
||||
return (hasWrapper(response) ? response : new RelativeRedirectResponseWrapper(response, redirectStatus));
|
||||
}
|
||||
|
||||
private static boolean hasWrapper(ServletResponse response) {
|
||||
|
||||
Reference in New Issue
Block a user