mirror of
https://github.com/spring-projects/spring-security.git
synced 2025-06-23 12:32:13 +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;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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() {
|
||||
return getHttpRequest().getRequestURL().toString()
|
||||
+ ((getHttpRequest().getQueryString() == null) ? ""
|
||||
: ("?"
|
||||
+ getHttpRequest().getQueryString()));
|
||||
return getHttpRequest().getScheme() + "://"
|
||||
+ getHttpRequest().getServerName() + ":"
|
||||
+ getHttpRequest().getServerPort() + getHttpRequest().getContextPath()
|
||||
+ getRequestUrl();
|
||||
}
|
||||
|
||||
public HttpServletRequest getHttpRequest() {
|
||||
@ -103,9 +113,10 @@ public class FilterInvocation {
|
||||
public String getRequestUrl() {
|
||||
String pathInfo = getHttpRequest().getPathInfo();
|
||||
String queryString = getHttpRequest().getQueryString();
|
||||
|
||||
return getHttpRequest().getServletPath() + (pathInfo == null ? "" : pathInfo)
|
||||
+ (queryString == null ? "" : ("?" + queryString));
|
||||
|
||||
return getHttpRequest().getServletPath()
|
||||
+ ((pathInfo == null) ? "" : pathInfo)
|
||||
+ ((queryString == null) ? "" : ("?" + queryString));
|
||||
}
|
||||
|
||||
public ServletResponse getResponse() {
|
||||
|
@ -69,7 +69,12 @@ public class FilterInvocationTests extends TestCase {
|
||||
MockHttpServletRequest request = new MockHttpServletRequest(null, null);
|
||||
request.setServletPath("/HelloWorld");
|
||||
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();
|
||||
MockFilterChain chain = new MockFilterChain();
|
||||
@ -80,8 +85,9 @@ public class FilterInvocationTests extends TestCase {
|
||||
assertEquals(response, fi.getHttpResponse());
|
||||
assertEquals(chain, fi.getChain());
|
||||
assertEquals("/HelloWorld/some/more/segments.html", fi.getRequestUrl());
|
||||
assertEquals("FilterInvocation: URL: /HelloWorld/some/more/segments.html", fi.toString());
|
||||
assertEquals("http://www.example.com/mycontext/HelloWorld/some/more/segments.html",
|
||||
assertEquals("FilterInvocation: URL: /HelloWorld/some/more/segments.html",
|
||||
fi.toString());
|
||||
assertEquals("http://www.example.com:80/mycontext/HelloWorld/some/more/segments.html",
|
||||
fi.getFullRequestUrl());
|
||||
}
|
||||
|
||||
@ -161,6 +167,10 @@ public class FilterInvocationTests extends TestCase {
|
||||
public void testStringMethodsWithAQueryString() {
|
||||
MockHttpServletRequest request = new MockHttpServletRequest("foo=bar");
|
||||
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");
|
||||
|
||||
MockHttpServletResponse response = new MockHttpServletResponse();
|
||||
@ -168,13 +178,17 @@ public class FilterInvocationTests extends TestCase {
|
||||
FilterInvocation fi = new FilterInvocation(request, response, chain);
|
||||
assertEquals("/HelloWorld?foo=bar", fi.getRequestUrl());
|
||||
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());
|
||||
}
|
||||
|
||||
public void testStringMethodsWithoutAnyQueryString() {
|
||||
MockHttpServletRequest request = new MockHttpServletRequest(null, null);
|
||||
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");
|
||||
|
||||
MockHttpServletResponse response = new MockHttpServletResponse();
|
||||
@ -182,7 +196,7 @@ public class FilterInvocationTests extends TestCase {
|
||||
FilterInvocation fi = new FilterInvocation(request, response, chain);
|
||||
assertEquals("/HelloWorld", fi.getRequestUrl());
|
||||
assertEquals("FilterInvocation: URL: /HelloWorld", fi.toString());
|
||||
assertEquals("http://www.example.com/mycontext/HelloWorld",
|
||||
assertEquals("http://www.example.com:80/mycontext/HelloWorld",
|
||||
fi.getFullRequestUrl());
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user