mirror of
https://github.com/spring-projects/spring-security.git
synced 2025-06-24 21:12:18 +00:00
Clarify how URLs are constructed.
This commit is contained in:
parent
8a4edca136
commit
c6a1b2b608
@ -81,11 +81,21 @@ public class FilterInvocation {
|
|||||||
return chain;
|
return chain;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Indicates the URL that the user agent used for this request.
|
||||||
|
*
|
||||||
|
* <P>
|
||||||
|
* The returned URL does <b>not</b> reflect the port number determined from
|
||||||
|
* a {@link net.sf.acegisecurity.util.PortResolver}.
|
||||||
|
* </p>
|
||||||
|
*
|
||||||
|
* @return the full URL of this request
|
||||||
|
*/
|
||||||
public String getFullRequestUrl() {
|
public String getFullRequestUrl() {
|
||||||
return getHttpRequest().getRequestURL().toString()
|
return getHttpRequest().getScheme() + "://"
|
||||||
+ ((getHttpRequest().getQueryString() == null) ? ""
|
+ getHttpRequest().getServerName() + ":"
|
||||||
: ("?"
|
+ getHttpRequest().getServerPort() + getHttpRequest().getContextPath()
|
||||||
+ getHttpRequest().getQueryString()));
|
+ getRequestUrl();
|
||||||
}
|
}
|
||||||
|
|
||||||
public HttpServletRequest getHttpRequest() {
|
public HttpServletRequest getHttpRequest() {
|
||||||
@ -104,8 +114,9 @@ public class FilterInvocation {
|
|||||||
String pathInfo = getHttpRequest().getPathInfo();
|
String pathInfo = getHttpRequest().getPathInfo();
|
||||||
String queryString = getHttpRequest().getQueryString();
|
String queryString = getHttpRequest().getQueryString();
|
||||||
|
|
||||||
return getHttpRequest().getServletPath() + (pathInfo == null ? "" : pathInfo)
|
return getHttpRequest().getServletPath()
|
||||||
+ (queryString == null ? "" : ("?" + queryString));
|
+ ((pathInfo == null) ? "" : pathInfo)
|
||||||
|
+ ((queryString == null) ? "" : ("?" + queryString));
|
||||||
}
|
}
|
||||||
|
|
||||||
public ServletResponse getResponse() {
|
public ServletResponse getResponse() {
|
||||||
|
@ -69,7 +69,12 @@ public class FilterInvocationTests extends TestCase {
|
|||||||
MockHttpServletRequest request = new MockHttpServletRequest(null, null);
|
MockHttpServletRequest request = new MockHttpServletRequest(null, null);
|
||||||
request.setServletPath("/HelloWorld");
|
request.setServletPath("/HelloWorld");
|
||||||
request.setPathInfo("/some/more/segments.html");
|
request.setPathInfo("/some/more/segments.html");
|
||||||
request.setRequestURL("http://www.example.com/mycontext/HelloWorld/some/more/segments.html");
|
request.setServerName("www.example.com");
|
||||||
|
request.setScheme("http");
|
||||||
|
request.setServerPort(80);
|
||||||
|
request.setContextPath("/mycontext");
|
||||||
|
request.setRequestURL(
|
||||||
|
"http://www.example.com/mycontext/HelloWorld/some/more/segments.html");
|
||||||
|
|
||||||
MockHttpServletResponse response = new MockHttpServletResponse();
|
MockHttpServletResponse response = new MockHttpServletResponse();
|
||||||
MockFilterChain chain = new MockFilterChain();
|
MockFilterChain chain = new MockFilterChain();
|
||||||
@ -80,8 +85,9 @@ public class FilterInvocationTests extends TestCase {
|
|||||||
assertEquals(response, fi.getHttpResponse());
|
assertEquals(response, fi.getHttpResponse());
|
||||||
assertEquals(chain, fi.getChain());
|
assertEquals(chain, fi.getChain());
|
||||||
assertEquals("/HelloWorld/some/more/segments.html", fi.getRequestUrl());
|
assertEquals("/HelloWorld/some/more/segments.html", fi.getRequestUrl());
|
||||||
assertEquals("FilterInvocation: URL: /HelloWorld/some/more/segments.html", fi.toString());
|
assertEquals("FilterInvocation: URL: /HelloWorld/some/more/segments.html",
|
||||||
assertEquals("http://www.example.com/mycontext/HelloWorld/some/more/segments.html",
|
fi.toString());
|
||||||
|
assertEquals("http://www.example.com:80/mycontext/HelloWorld/some/more/segments.html",
|
||||||
fi.getFullRequestUrl());
|
fi.getFullRequestUrl());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -161,6 +167,10 @@ public class FilterInvocationTests extends TestCase {
|
|||||||
public void testStringMethodsWithAQueryString() {
|
public void testStringMethodsWithAQueryString() {
|
||||||
MockHttpServletRequest request = new MockHttpServletRequest("foo=bar");
|
MockHttpServletRequest request = new MockHttpServletRequest("foo=bar");
|
||||||
request.setServletPath("/HelloWorld");
|
request.setServletPath("/HelloWorld");
|
||||||
|
request.setServerName("www.example.com");
|
||||||
|
request.setScheme("http");
|
||||||
|
request.setServerPort(80);
|
||||||
|
request.setContextPath("/mycontext");
|
||||||
request.setRequestURL("http://www.example.com/mycontext/HelloWorld");
|
request.setRequestURL("http://www.example.com/mycontext/HelloWorld");
|
||||||
|
|
||||||
MockHttpServletResponse response = new MockHttpServletResponse();
|
MockHttpServletResponse response = new MockHttpServletResponse();
|
||||||
@ -168,13 +178,17 @@ public class FilterInvocationTests extends TestCase {
|
|||||||
FilterInvocation fi = new FilterInvocation(request, response, chain);
|
FilterInvocation fi = new FilterInvocation(request, response, chain);
|
||||||
assertEquals("/HelloWorld?foo=bar", fi.getRequestUrl());
|
assertEquals("/HelloWorld?foo=bar", fi.getRequestUrl());
|
||||||
assertEquals("FilterInvocation: URL: /HelloWorld?foo=bar", fi.toString());
|
assertEquals("FilterInvocation: URL: /HelloWorld?foo=bar", fi.toString());
|
||||||
assertEquals("http://www.example.com/mycontext/HelloWorld?foo=bar",
|
assertEquals("http://www.example.com:80/mycontext/HelloWorld?foo=bar",
|
||||||
fi.getFullRequestUrl());
|
fi.getFullRequestUrl());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testStringMethodsWithoutAnyQueryString() {
|
public void testStringMethodsWithoutAnyQueryString() {
|
||||||
MockHttpServletRequest request = new MockHttpServletRequest(null, null);
|
MockHttpServletRequest request = new MockHttpServletRequest(null, null);
|
||||||
request.setServletPath("/HelloWorld");
|
request.setServletPath("/HelloWorld");
|
||||||
|
request.setServerName("www.example.com");
|
||||||
|
request.setScheme("http");
|
||||||
|
request.setServerPort(80);
|
||||||
|
request.setContextPath("/mycontext");
|
||||||
request.setRequestURL("http://www.example.com/mycontext/HelloWorld");
|
request.setRequestURL("http://www.example.com/mycontext/HelloWorld");
|
||||||
|
|
||||||
MockHttpServletResponse response = new MockHttpServletResponse();
|
MockHttpServletResponse response = new MockHttpServletResponse();
|
||||||
@ -182,7 +196,7 @@ public class FilterInvocationTests extends TestCase {
|
|||||||
FilterInvocation fi = new FilterInvocation(request, response, chain);
|
FilterInvocation fi = new FilterInvocation(request, response, chain);
|
||||||
assertEquals("/HelloWorld", fi.getRequestUrl());
|
assertEquals("/HelloWorld", fi.getRequestUrl());
|
||||||
assertEquals("FilterInvocation: URL: /HelloWorld", fi.toString());
|
assertEquals("FilterInvocation: URL: /HelloWorld", fi.toString());
|
||||||
assertEquals("http://www.example.com/mycontext/HelloWorld",
|
assertEquals("http://www.example.com:80/mycontext/HelloWorld",
|
||||||
fi.getFullRequestUrl());
|
fi.getFullRequestUrl());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user