Polishing

This commit is contained in:
Juergen Hoeller
2017-07-19 22:22:27 +02:00
parent 46eba3dbfa
commit ac1d3b22c9
10 changed files with 38 additions and 41 deletions

View File

@@ -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);
}
}

View File

@@ -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;
}

View File

@@ -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) {

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2016 the original author or authors.
* Copyright 2002-2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -32,10 +32,7 @@ import org.springframework.mock.web.test.MockFilterChain;
import org.springframework.mock.web.test.MockHttpServletRequest;
import org.springframework.mock.web.test.MockHttpServletResponse;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.*;
/**
* Unit tests for {@link ForwardedHeaderFilter}.
@@ -61,7 +58,7 @@ public class ForwardedHeaderFilterTests {
@Before
@SuppressWarnings("serial")
public void setUp() throws Exception {
public void setup() throws Exception {
this.request = new MockHttpServletRequest();
this.request.setScheme("http");
this.request.setServerName("localhost");

View File

@@ -32,11 +32,11 @@ import org.springframework.mock.web.test.MockFilterChain;
import org.springframework.mock.web.test.MockHttpServletRequest;
import org.springframework.mock.web.test.MockHttpServletResponse;
import static org.junit.Assert.assertNotSame;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.*;
/**
* Unit tests for {@link RelativeRedirectFilter}.
*
* @author Rob Winch
*/
@RunWith(MockitoJUnitRunner.class)
@@ -110,4 +110,5 @@ public class RelativeRedirectFilterTests {
HttpServletResponse wrappedResponse = (HttpServletResponse) chain.getResponse();
wrappedResponse.sendRedirect(location);
}
}
}