|
|
|
|
@ -31,7 +31,6 @@ import org.springframework.http.HttpRequest;
@@ -31,7 +31,6 @@ import org.springframework.http.HttpRequest;
|
|
|
|
|
import org.springframework.http.server.ServletServerHttpRequest; |
|
|
|
|
import org.springframework.util.LinkedMultiValueMap; |
|
|
|
|
import org.springframework.util.MultiValueMap; |
|
|
|
|
import org.springframework.util.StringUtils; |
|
|
|
|
import org.springframework.web.testfixture.servlet.MockHttpServletRequest; |
|
|
|
|
|
|
|
|
|
import static org.assertj.core.api.Assertions.assertThat; |
|
|
|
|
@ -48,10 +47,10 @@ import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException
@@ -48,10 +47,10 @@ import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException
|
|
|
|
|
* @author Sam Brannen |
|
|
|
|
* @author David Eckel |
|
|
|
|
*/ |
|
|
|
|
public class UriComponentsBuilderTests { |
|
|
|
|
class UriComponentsBuilderTests { |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
public void plain() throws URISyntaxException { |
|
|
|
|
void plain() throws URISyntaxException { |
|
|
|
|
UriComponentsBuilder builder = UriComponentsBuilder.newInstance(); |
|
|
|
|
UriComponents result = builder.scheme("https").host("example.com") |
|
|
|
|
.path("foo").queryParam("bar").fragment("baz") |
|
|
|
|
@ -67,7 +66,7 @@ public class UriComponentsBuilderTests {
@@ -67,7 +66,7 @@ public class UriComponentsBuilderTests {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
public void multipleFromSameBuilder() throws URISyntaxException { |
|
|
|
|
void multipleFromSameBuilder() throws URISyntaxException { |
|
|
|
|
UriComponentsBuilder builder = UriComponentsBuilder.newInstance() |
|
|
|
|
.scheme("https").host("example.com").pathSegment("foo"); |
|
|
|
|
UriComponents result1 = builder.build(); |
|
|
|
|
@ -90,7 +89,7 @@ public class UriComponentsBuilderTests {
@@ -90,7 +89,7 @@ public class UriComponentsBuilderTests {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
public void fromPath() throws URISyntaxException { |
|
|
|
|
void fromPath() throws URISyntaxException { |
|
|
|
|
UriComponents result = UriComponentsBuilder.fromPath("foo").queryParam("bar").fragment("baz").build(); |
|
|
|
|
assertThat(result.getPath()).isEqualTo("foo"); |
|
|
|
|
assertThat(result.getQuery()).isEqualTo("bar"); |
|
|
|
|
@ -109,7 +108,7 @@ public class UriComponentsBuilderTests {
@@ -109,7 +108,7 @@ public class UriComponentsBuilderTests {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
public void fromHierarchicalUri() throws URISyntaxException { |
|
|
|
|
void fromHierarchicalUri() throws URISyntaxException { |
|
|
|
|
URI uri = new URI("https://example.com/foo?bar#baz"); |
|
|
|
|
UriComponents result = UriComponentsBuilder.fromUri(uri).build(); |
|
|
|
|
assertThat(result.getScheme()).isEqualTo("https"); |
|
|
|
|
@ -122,7 +121,7 @@ public class UriComponentsBuilderTests {
@@ -122,7 +121,7 @@ public class UriComponentsBuilderTests {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
public void fromOpaqueUri() throws URISyntaxException { |
|
|
|
|
void fromOpaqueUri() throws URISyntaxException { |
|
|
|
|
URI uri = new URI("mailto:foo@bar.com#baz"); |
|
|
|
|
UriComponents result = UriComponentsBuilder.fromUri(uri).build(); |
|
|
|
|
assertThat(result.getScheme()).isEqualTo("mailto"); |
|
|
|
|
@ -133,7 +132,7 @@ public class UriComponentsBuilderTests {
@@ -133,7 +132,7 @@ public class UriComponentsBuilderTests {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test // SPR-9317
|
|
|
|
|
public void fromUriEncodedQuery() throws URISyntaxException { |
|
|
|
|
void fromUriEncodedQuery() throws URISyntaxException { |
|
|
|
|
URI uri = new URI("https://www.example.org/?param=aGVsbG9Xb3JsZA%3D%3D"); |
|
|
|
|
String fromUri = UriComponentsBuilder.fromUri(uri).build().getQueryParams().get("param").get(0); |
|
|
|
|
String fromUriString = UriComponentsBuilder.fromUriString(uri.toString()) |
|
|
|
|
@ -143,7 +142,7 @@ public class UriComponentsBuilderTests {
@@ -143,7 +142,7 @@ public class UriComponentsBuilderTests {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
public void fromUriString() { |
|
|
|
|
void fromUriString() { |
|
|
|
|
UriComponents result = UriComponentsBuilder.fromUriString("https://www.ietf.org/rfc/rfc3986.txt").build(); |
|
|
|
|
assertThat(result.getScheme()).isEqualTo("https"); |
|
|
|
|
assertThat(result.getUserInfo()).isNull(); |
|
|
|
|
@ -189,7 +188,7 @@ public class UriComponentsBuilderTests {
@@ -189,7 +188,7 @@ public class UriComponentsBuilderTests {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test // SPR-9832
|
|
|
|
|
public void fromUriStringQueryParamWithReservedCharInValue() { |
|
|
|
|
void fromUriStringQueryParamWithReservedCharInValue() { |
|
|
|
|
String uri = "https://www.google.com/ig/calculator?q=1USD=?EUR"; |
|
|
|
|
UriComponents result = UriComponentsBuilder.fromUriString(uri).build(); |
|
|
|
|
|
|
|
|
|
@ -198,27 +197,15 @@ public class UriComponentsBuilderTests {
@@ -198,27 +197,15 @@ public class UriComponentsBuilderTests {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test // SPR-14828
|
|
|
|
|
public void fromUriStringQueryParamEncodedAndContainingPlus() { |
|
|
|
|
void fromUriStringQueryParamEncodedAndContainingPlus() { |
|
|
|
|
String httpUrl = "http://localhost:8080/test/print?value=%EA%B0%80+%EB%82%98"; |
|
|
|
|
URI uri = UriComponentsBuilder.fromHttpUrl(httpUrl).build(true).toUri(); |
|
|
|
|
URI uri = UriComponentsBuilder.fromUriString(httpUrl).build(true).toUri(); |
|
|
|
|
|
|
|
|
|
assertThat(uri.toString()).isEqualTo(httpUrl); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test // SPR-10779
|
|
|
|
|
public void fromHttpUrlStringCaseInsesitiveScheme() { |
|
|
|
|
assertThat(UriComponentsBuilder.fromHttpUrl("HTTP://www.google.com").build().getScheme()).isEqualTo("http"); |
|
|
|
|
assertThat(UriComponentsBuilder.fromHttpUrl("HTTPS://www.google.com").build().getScheme()).isEqualTo("https"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test // SPR-10539
|
|
|
|
|
public void fromHttpUrlStringInvalidIPv6Host() { |
|
|
|
|
assertThatIllegalArgumentException().isThrownBy(() -> |
|
|
|
|
UriComponentsBuilder.fromHttpUrl("http://[1abc:2abc:3abc::5ABC:6abc:8080/resource").build().encode()); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test // SPR-10539
|
|
|
|
|
public void fromUriStringIPv6Host() { |
|
|
|
|
void fromUriStringIPv6Host() { |
|
|
|
|
UriComponents result = UriComponentsBuilder |
|
|
|
|
.fromUriString("http://[1abc:2abc:3abc::5ABC:6abc]:8080/resource").build().encode(); |
|
|
|
|
assertThat(result.getHost()).isEqualTo("[1abc:2abc:3abc::5ABC:6abc]"); |
|
|
|
|
@ -233,16 +220,36 @@ public class UriComponentsBuilderTests {
@@ -233,16 +220,36 @@ public class UriComponentsBuilderTests {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test // SPR-11970
|
|
|
|
|
public void fromUriStringNoPathWithReservedCharInQuery() { |
|
|
|
|
void fromUriStringNoPathWithReservedCharInQuery() { |
|
|
|
|
UriComponents result = UriComponentsBuilder.fromUriString("https://example.com?foo=bar@baz").build(); |
|
|
|
|
assertThat(StringUtils.isEmpty(result.getUserInfo())).isTrue(); |
|
|
|
|
assertThat(result.getUserInfo()).isNull(); |
|
|
|
|
assertThat(result.getHost()).isEqualTo("example.com"); |
|
|
|
|
assertThat(result.getQueryParams().containsKey("foo")).isTrue(); |
|
|
|
|
assertThat(result.getQueryParams()).containsKey("foo"); |
|
|
|
|
assertThat(result.getQueryParams().getFirst("foo")).isEqualTo("bar@baz"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test // SPR-14828
|
|
|
|
|
void fromHttpUrlQueryParamEncodedAndContainingPlus() { |
|
|
|
|
String httpUrl = "http://localhost:8080/test/print?value=%EA%B0%80+%EB%82%98"; |
|
|
|
|
URI uri = UriComponentsBuilder.fromHttpUrl(httpUrl).build(true).toUri(); |
|
|
|
|
|
|
|
|
|
assertThat(uri.toString()).isEqualTo(httpUrl); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test // SPR-10779
|
|
|
|
|
void fromHttpUrlCaseInsensitiveScheme() { |
|
|
|
|
assertThat(UriComponentsBuilder.fromHttpUrl("HTTP://www.google.com").build().getScheme()).isEqualTo("http"); |
|
|
|
|
assertThat(UriComponentsBuilder.fromHttpUrl("HTTPS://www.google.com").build().getScheme()).isEqualTo("https"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test // SPR-10539
|
|
|
|
|
void fromHttpUrlInvalidIPv6Host() { |
|
|
|
|
assertThatIllegalArgumentException().isThrownBy(() -> |
|
|
|
|
UriComponentsBuilder.fromHttpUrl("http://[1abc:2abc:3abc::5ABC:6abc:8080/resource")); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
public void fromHttpRequest() { |
|
|
|
|
void fromHttpRequest() { |
|
|
|
|
MockHttpServletRequest request = new MockHttpServletRequest(); |
|
|
|
|
request.setScheme("http"); |
|
|
|
|
request.setServerName("localhost"); |
|
|
|
|
@ -259,7 +266,7 @@ public class UriComponentsBuilderTests {
@@ -259,7 +266,7 @@ public class UriComponentsBuilderTests {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test // SPR-12771
|
|
|
|
|
public void fromHttpRequestResetsPortBeforeSettingIt() { |
|
|
|
|
void fromHttpRequestResetsPortBeforeSettingIt() { |
|
|
|
|
MockHttpServletRequest request = new MockHttpServletRequest(); |
|
|
|
|
request.addHeader("X-Forwarded-Proto", "https"); |
|
|
|
|
request.addHeader("X-Forwarded-Host", "84.198.58.199"); |
|
|
|
|
@ -279,7 +286,7 @@ public class UriComponentsBuilderTests {
@@ -279,7 +286,7 @@ public class UriComponentsBuilderTests {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test // SPR-14761
|
|
|
|
|
public void fromHttpRequestWithForwardedIPv4Host() { |
|
|
|
|
void fromHttpRequestWithForwardedIPv4Host() { |
|
|
|
|
MockHttpServletRequest request = new MockHttpServletRequest(); |
|
|
|
|
request.setScheme("https"); |
|
|
|
|
request.setServerName("localhost"); |
|
|
|
|
@ -294,7 +301,7 @@ public class UriComponentsBuilderTests {
@@ -294,7 +301,7 @@ public class UriComponentsBuilderTests {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test // SPR-14761
|
|
|
|
|
public void fromHttpRequestWithForwardedIPv6() { |
|
|
|
|
void fromHttpRequestWithForwardedIPv6() { |
|
|
|
|
MockHttpServletRequest request = new MockHttpServletRequest(); |
|
|
|
|
request.setScheme("http"); |
|
|
|
|
request.setServerName("localhost"); |
|
|
|
|
@ -309,7 +316,7 @@ public class UriComponentsBuilderTests {
@@ -309,7 +316,7 @@ public class UriComponentsBuilderTests {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test // SPR-14761
|
|
|
|
|
public void fromHttpRequestWithForwardedIPv6Host() { |
|
|
|
|
void fromHttpRequestWithForwardedIPv6Host() { |
|
|
|
|
MockHttpServletRequest request = new MockHttpServletRequest(); |
|
|
|
|
request.setScheme("http"); |
|
|
|
|
request.setServerName("localhost"); |
|
|
|
|
@ -324,7 +331,7 @@ public class UriComponentsBuilderTests {
@@ -324,7 +331,7 @@ public class UriComponentsBuilderTests {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test // SPR-14761
|
|
|
|
|
public void fromHttpRequestWithForwardedIPv6HostAndPort() { |
|
|
|
|
void fromHttpRequestWithForwardedIPv6HostAndPort() { |
|
|
|
|
MockHttpServletRequest request = new MockHttpServletRequest(); |
|
|
|
|
request.setScheme("http"); |
|
|
|
|
request.setServerName("localhost"); |
|
|
|
|
@ -339,7 +346,7 @@ public class UriComponentsBuilderTests {
@@ -339,7 +346,7 @@ public class UriComponentsBuilderTests {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
public void fromHttpRequestWithForwardedHost() { |
|
|
|
|
void fromHttpRequestWithForwardedHost() { |
|
|
|
|
MockHttpServletRequest request = new MockHttpServletRequest(); |
|
|
|
|
request.setScheme("https"); |
|
|
|
|
request.setServerName("localhost"); |
|
|
|
|
@ -354,7 +361,7 @@ public class UriComponentsBuilderTests {
@@ -354,7 +361,7 @@ public class UriComponentsBuilderTests {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test // SPR-10701
|
|
|
|
|
public void fromHttpRequestWithForwardedHostIncludingPort() { |
|
|
|
|
void fromHttpRequestWithForwardedHostIncludingPort() { |
|
|
|
|
MockHttpServletRequest request = new MockHttpServletRequest(); |
|
|
|
|
request.setScheme("http"); |
|
|
|
|
request.setServerName("localhost"); |
|
|
|
|
@ -370,7 +377,7 @@ public class UriComponentsBuilderTests {
@@ -370,7 +377,7 @@ public class UriComponentsBuilderTests {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test // SPR-11140
|
|
|
|
|
public void fromHttpRequestWithForwardedHostMultiValuedHeader() { |
|
|
|
|
void fromHttpRequestWithForwardedHostMultiValuedHeader() { |
|
|
|
|
MockHttpServletRequest request = new MockHttpServletRequest(); |
|
|
|
|
request.setScheme("http"); |
|
|
|
|
request.setServerName("localhost"); |
|
|
|
|
@ -385,7 +392,7 @@ public class UriComponentsBuilderTests {
@@ -385,7 +392,7 @@ public class UriComponentsBuilderTests {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test // SPR-11855
|
|
|
|
|
public void fromHttpRequestWithForwardedHostAndPort() { |
|
|
|
|
void fromHttpRequestWithForwardedHostAndPort() { |
|
|
|
|
MockHttpServletRequest request = new MockHttpServletRequest(); |
|
|
|
|
request.setScheme("http"); |
|
|
|
|
request.setServerName("localhost"); |
|
|
|
|
@ -401,7 +408,7 @@ public class UriComponentsBuilderTests {
@@ -401,7 +408,7 @@ public class UriComponentsBuilderTests {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test // SPR-11872
|
|
|
|
|
public void fromHttpRequestWithForwardedHostWithDefaultPort() { |
|
|
|
|
void fromHttpRequestWithForwardedHostWithDefaultPort() { |
|
|
|
|
MockHttpServletRequest request = new MockHttpServletRequest(); |
|
|
|
|
request.setScheme("http"); |
|
|
|
|
request.setServerName("localhost"); |
|
|
|
|
@ -416,7 +423,7 @@ public class UriComponentsBuilderTests {
@@ -416,7 +423,7 @@ public class UriComponentsBuilderTests {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test // SPR-16262
|
|
|
|
|
public void fromHttpRequestWithForwardedProtoWithDefaultPort() { |
|
|
|
|
void fromHttpRequestWithForwardedProtoWithDefaultPort() { |
|
|
|
|
MockHttpServletRequest request = new MockHttpServletRequest(); |
|
|
|
|
request.setScheme("http"); |
|
|
|
|
request.setServerName("example.org"); |
|
|
|
|
@ -432,7 +439,7 @@ public class UriComponentsBuilderTests {
@@ -432,7 +439,7 @@ public class UriComponentsBuilderTests {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test // SPR-16863
|
|
|
|
|
public void fromHttpRequestWithForwardedSsl() { |
|
|
|
|
void fromHttpRequestWithForwardedSsl() { |
|
|
|
|
MockHttpServletRequest request = new MockHttpServletRequest(); |
|
|
|
|
request.setScheme("http"); |
|
|
|
|
request.setServerName("example.org"); |
|
|
|
|
@ -448,7 +455,7 @@ public class UriComponentsBuilderTests {
@@ -448,7 +455,7 @@ public class UriComponentsBuilderTests {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
public void fromHttpRequestWithForwardedHostWithForwardedScheme() { |
|
|
|
|
void fromHttpRequestWithForwardedHostWithForwardedScheme() { |
|
|
|
|
MockHttpServletRequest request = new MockHttpServletRequest(); |
|
|
|
|
request.setScheme("http"); |
|
|
|
|
request.setServerName("localhost"); |
|
|
|
|
@ -465,7 +472,7 @@ public class UriComponentsBuilderTests {
@@ -465,7 +472,7 @@ public class UriComponentsBuilderTests {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test // SPR-12771
|
|
|
|
|
public void fromHttpRequestWithForwardedProtoAndDefaultPort() { |
|
|
|
|
void fromHttpRequestWithForwardedProtoAndDefaultPort() { |
|
|
|
|
MockHttpServletRequest request = new MockHttpServletRequest(); |
|
|
|
|
request.setScheme("http"); |
|
|
|
|
request.setServerName("localhost"); |
|
|
|
|
@ -482,7 +489,7 @@ public class UriComponentsBuilderTests {
@@ -482,7 +489,7 @@ public class UriComponentsBuilderTests {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test // SPR-12813
|
|
|
|
|
public void fromHttpRequestWithForwardedPortMultiValueHeader() { |
|
|
|
|
void fromHttpRequestWithForwardedPortMultiValueHeader() { |
|
|
|
|
MockHttpServletRequest request = new MockHttpServletRequest(); |
|
|
|
|
request.setScheme("http"); |
|
|
|
|
request.setServerName("localhost"); |
|
|
|
|
@ -498,7 +505,7 @@ public class UriComponentsBuilderTests {
@@ -498,7 +505,7 @@ public class UriComponentsBuilderTests {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test // SPR-12816
|
|
|
|
|
public void fromHttpRequestWithForwardedProtoMultiValueHeader() { |
|
|
|
|
void fromHttpRequestWithForwardedProtoMultiValueHeader() { |
|
|
|
|
MockHttpServletRequest request = new MockHttpServletRequest(); |
|
|
|
|
request.setScheme("http"); |
|
|
|
|
request.setServerName("localhost"); |
|
|
|
|
@ -515,14 +522,14 @@ public class UriComponentsBuilderTests {
@@ -515,14 +522,14 @@ public class UriComponentsBuilderTests {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test // SPR-12742
|
|
|
|
|
public void fromHttpRequestWithTrailingSlash() { |
|
|
|
|
void fromHttpRequestWithTrailingSlash() { |
|
|
|
|
UriComponents before = UriComponentsBuilder.fromPath("/foo/").build(); |
|
|
|
|
UriComponents after = UriComponentsBuilder.newInstance().uriComponents(before).build(); |
|
|
|
|
assertThat(after.getPath()).isEqualTo("/foo/"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test // gh-19890
|
|
|
|
|
public void fromHttpRequestWithEmptyScheme() { |
|
|
|
|
void fromHttpRequestWithEmptyScheme() { |
|
|
|
|
HttpRequest request = new HttpRequest() { |
|
|
|
|
@Override |
|
|
|
|
public String getMethodValue() { |
|
|
|
|
@ -545,7 +552,7 @@ public class UriComponentsBuilderTests {
@@ -545,7 +552,7 @@ public class UriComponentsBuilderTests {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
public void path() { |
|
|
|
|
void path() { |
|
|
|
|
UriComponentsBuilder builder = UriComponentsBuilder.fromPath("/foo/bar"); |
|
|
|
|
UriComponents result = builder.build(); |
|
|
|
|
|
|
|
|
|
@ -554,7 +561,7 @@ public class UriComponentsBuilderTests {
@@ -554,7 +561,7 @@ public class UriComponentsBuilderTests {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
public void pathSegments() { |
|
|
|
|
void pathSegments() { |
|
|
|
|
UriComponentsBuilder builder = UriComponentsBuilder.newInstance(); |
|
|
|
|
UriComponents result = builder.pathSegment("foo").pathSegment("bar").build(); |
|
|
|
|
|
|
|
|
|
@ -563,7 +570,7 @@ public class UriComponentsBuilderTests {
@@ -563,7 +570,7 @@ public class UriComponentsBuilderTests {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
public void pathThenPath() { |
|
|
|
|
void pathThenPath() { |
|
|
|
|
UriComponentsBuilder builder = UriComponentsBuilder.fromPath("/foo/bar").path("ba/z"); |
|
|
|
|
UriComponents result = builder.build().encode(); |
|
|
|
|
|
|
|
|
|
@ -572,7 +579,7 @@ public class UriComponentsBuilderTests {
@@ -572,7 +579,7 @@ public class UriComponentsBuilderTests {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
public void pathThenPathSegments() { |
|
|
|
|
void pathThenPathSegments() { |
|
|
|
|
UriComponentsBuilder builder = UriComponentsBuilder.fromPath("/foo/bar").pathSegment("ba/z"); |
|
|
|
|
UriComponents result = builder.build().encode(); |
|
|
|
|
|
|
|
|
|
@ -581,7 +588,7 @@ public class UriComponentsBuilderTests {
@@ -581,7 +588,7 @@ public class UriComponentsBuilderTests {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
public void pathSegmentsThenPathSegments() { |
|
|
|
|
void pathSegmentsThenPathSegments() { |
|
|
|
|
UriComponentsBuilder builder = UriComponentsBuilder.newInstance().pathSegment("foo").pathSegment("bar"); |
|
|
|
|
UriComponents result = builder.build(); |
|
|
|
|
|
|
|
|
|
@ -590,7 +597,7 @@ public class UriComponentsBuilderTests {
@@ -590,7 +597,7 @@ public class UriComponentsBuilderTests {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
public void pathSegmentsThenPath() { |
|
|
|
|
void pathSegmentsThenPath() { |
|
|
|
|
UriComponentsBuilder builder = UriComponentsBuilder.newInstance().pathSegment("foo").path("/"); |
|
|
|
|
UriComponents result = builder.build(); |
|
|
|
|
|
|
|
|
|
@ -599,7 +606,7 @@ public class UriComponentsBuilderTests {
@@ -599,7 +606,7 @@ public class UriComponentsBuilderTests {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
public void pathSegmentsSomeEmpty() { |
|
|
|
|
void pathSegmentsSomeEmpty() { |
|
|
|
|
UriComponentsBuilder builder = UriComponentsBuilder.newInstance().pathSegment("", "foo", "", "bar"); |
|
|
|
|
UriComponents result = builder.build(); |
|
|
|
|
|
|
|
|
|
@ -608,13 +615,13 @@ public class UriComponentsBuilderTests {
@@ -608,13 +615,13 @@ public class UriComponentsBuilderTests {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test // SPR-12398
|
|
|
|
|
public void pathWithDuplicateSlashes() { |
|
|
|
|
void pathWithDuplicateSlashes() { |
|
|
|
|
UriComponents uriComponents = UriComponentsBuilder.fromPath("/foo/////////bar").build(); |
|
|
|
|
assertThat(uriComponents.getPath()).isEqualTo("/foo/bar"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
public void replacePath() { |
|
|
|
|
void replacePath() { |
|
|
|
|
UriComponentsBuilder builder = UriComponentsBuilder.fromUriString("https://www.ietf.org/rfc/rfc2396.txt"); |
|
|
|
|
builder.replacePath("/rfc/rfc3986.txt"); |
|
|
|
|
UriComponents result = builder.build(); |
|
|
|
|
@ -629,7 +636,7 @@ public class UriComponentsBuilderTests {
@@ -629,7 +636,7 @@ public class UriComponentsBuilderTests {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
public void replaceQuery() { |
|
|
|
|
void replaceQuery() { |
|
|
|
|
UriComponentsBuilder builder = UriComponentsBuilder.fromUriString("https://example.com/foo?foo=bar&baz=qux"); |
|
|
|
|
builder.replaceQuery("baz=42"); |
|
|
|
|
UriComponents result = builder.build(); |
|
|
|
|
@ -644,7 +651,7 @@ public class UriComponentsBuilderTests {
@@ -644,7 +651,7 @@ public class UriComponentsBuilderTests {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
public void queryParam() { |
|
|
|
|
void queryParam() { |
|
|
|
|
UriComponents result = UriComponentsBuilder.newInstance().queryParam("baz", "qux", 42).build(); |
|
|
|
|
|
|
|
|
|
assertThat(result.getQuery()).isEqualTo("baz=qux&baz=42"); |
|
|
|
|
@ -655,7 +662,7 @@ public class UriComponentsBuilderTests {
@@ -655,7 +662,7 @@ public class UriComponentsBuilderTests {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
public void queryParamWithList() { |
|
|
|
|
void queryParamWithList() { |
|
|
|
|
UriComponentsBuilder builder = UriComponentsBuilder.newInstance(); |
|
|
|
|
UriComponents result = builder.queryParam("baz", Arrays.asList("qux", 42)).build(); |
|
|
|
|
|
|
|
|
|
@ -667,7 +674,7 @@ public class UriComponentsBuilderTests {
@@ -667,7 +674,7 @@ public class UriComponentsBuilderTests {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
public void emptyQueryParam() { |
|
|
|
|
void emptyQueryParam() { |
|
|
|
|
UriComponentsBuilder builder = UriComponentsBuilder.newInstance(); |
|
|
|
|
UriComponents result = builder.queryParam("baz").build(); |
|
|
|
|
|
|
|
|
|
@ -678,7 +685,7 @@ public class UriComponentsBuilderTests {
@@ -678,7 +685,7 @@ public class UriComponentsBuilderTests {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
public void emptyQueryParams() { |
|
|
|
|
void emptyQueryParams() { |
|
|
|
|
UriComponents result = UriComponentsBuilder.newInstance() |
|
|
|
|
.queryParam("baz", Collections.emptyList()) |
|
|
|
|
.queryParam("foo", (Collection<?>) null) |
|
|
|
|
@ -692,7 +699,7 @@ public class UriComponentsBuilderTests {
@@ -692,7 +699,7 @@ public class UriComponentsBuilderTests {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
public void replaceQueryParam() { |
|
|
|
|
void replaceQueryParam() { |
|
|
|
|
UriComponentsBuilder builder = UriComponentsBuilder.newInstance().queryParam("baz", "qux", 42); |
|
|
|
|
builder.replaceQueryParam("baz", "xuq", 24); |
|
|
|
|
UriComponents result = builder.build(); |
|
|
|
|
@ -707,7 +714,7 @@ public class UriComponentsBuilderTests {
@@ -707,7 +714,7 @@ public class UriComponentsBuilderTests {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
public void replaceQueryParams() { |
|
|
|
|
void replaceQueryParams() { |
|
|
|
|
UriComponentsBuilder builder = UriComponentsBuilder.newInstance().queryParam("baz", Arrays.asList("qux", 42)); |
|
|
|
|
builder.replaceQueryParam("baz", Arrays.asList("xuq", 24)); |
|
|
|
|
UriComponents result = builder.build(); |
|
|
|
|
@ -722,7 +729,7 @@ public class UriComponentsBuilderTests {
@@ -722,7 +729,7 @@ public class UriComponentsBuilderTests {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
public void buildAndExpandHierarchical() { |
|
|
|
|
void buildAndExpandHierarchical() { |
|
|
|
|
UriComponents result = UriComponentsBuilder.fromPath("/{foo}").buildAndExpand("fooValue"); |
|
|
|
|
assertThat(result.toUriString()).isEqualTo("/fooValue"); |
|
|
|
|
|
|
|
|
|
@ -734,7 +741,7 @@ public class UriComponentsBuilderTests {
@@ -734,7 +741,7 @@ public class UriComponentsBuilderTests {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
public void buildAndExpandOpaque() { |
|
|
|
|
void buildAndExpandOpaque() { |
|
|
|
|
UriComponents result = UriComponentsBuilder.fromUriString("mailto:{user}@{domain}") |
|
|
|
|
.buildAndExpand("foo", "example.com"); |
|
|
|
|
assertThat(result.toUriString()).isEqualTo("mailto:foo@example.com"); |
|
|
|
|
@ -747,21 +754,21 @@ public class UriComponentsBuilderTests {
@@ -747,21 +754,21 @@ public class UriComponentsBuilderTests {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
public void queryParamWithValueWithEquals() { |
|
|
|
|
void queryParamWithValueWithEquals() { |
|
|
|
|
UriComponents uriComponents = UriComponentsBuilder.fromUriString("https://example.com/foo?bar=baz").build(); |
|
|
|
|
assertThat(uriComponents.toUriString()).isEqualTo("https://example.com/foo?bar=baz"); |
|
|
|
|
assertThat(uriComponents.getQueryParams().get("bar").get(0)).isEqualTo("baz"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
public void queryParamWithoutValueWithEquals() { |
|
|
|
|
void queryParamWithoutValueWithEquals() { |
|
|
|
|
UriComponents uriComponents = UriComponentsBuilder.fromUriString("https://example.com/foo?bar=").build(); |
|
|
|
|
assertThat(uriComponents.toUriString()).isEqualTo("https://example.com/foo?bar="); |
|
|
|
|
assertThat(uriComponents.getQueryParams().get("bar").get(0)).isEqualTo(""); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
public void queryParamWithoutValueWithoutEquals() { |
|
|
|
|
void queryParamWithoutValueWithoutEquals() { |
|
|
|
|
UriComponents uriComponents = UriComponentsBuilder.fromUriString("https://example.com/foo?bar").build(); |
|
|
|
|
assertThat(uriComponents.toUriString()).isEqualTo("https://example.com/foo?bar"); |
|
|
|
|
|
|
|
|
|
@ -770,7 +777,7 @@ public class UriComponentsBuilderTests {
@@ -770,7 +777,7 @@ public class UriComponentsBuilderTests {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test // gh-24444
|
|
|
|
|
public void opaqueUriDoesNotResetOnNullInput() throws URISyntaxException { |
|
|
|
|
void opaqueUriDoesNotResetOnNullInput() throws URISyntaxException { |
|
|
|
|
URI uri = new URI("urn:ietf:wg:oauth:2.0:oob"); |
|
|
|
|
UriComponents result = UriComponentsBuilder.fromUri(uri) |
|
|
|
|
.host(null) |
|
|
|
|
@ -785,7 +792,7 @@ public class UriComponentsBuilderTests {
@@ -785,7 +792,7 @@ public class UriComponentsBuilderTests {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
public void relativeUrls() { |
|
|
|
|
void relativeUrls() { |
|
|
|
|
String baseUrl = "https://example.com"; |
|
|
|
|
assertThat(UriComponentsBuilder.fromUriString(baseUrl + "/foo/../bar").build().toString()) |
|
|
|
|
.isEqualTo(baseUrl + "/foo/../bar"); |
|
|
|
|
@ -808,7 +815,7 @@ public class UriComponentsBuilderTests {
@@ -808,7 +815,7 @@ public class UriComponentsBuilderTests {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
public void emptySegments() { |
|
|
|
|
void emptySegments() { |
|
|
|
|
String baseUrl = "https://example.com/abc/"; |
|
|
|
|
assertThat(UriComponentsBuilder.fromUriString(baseUrl).path("/x/y/z").build().toString()) |
|
|
|
|
.isEqualTo("https://example.com/abc/x/y/z"); |
|
|
|
|
@ -821,20 +828,20 @@ public class UriComponentsBuilderTests {
@@ -821,20 +828,20 @@ public class UriComponentsBuilderTests {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
public void parsesEmptyFragment() { |
|
|
|
|
void parsesEmptyFragment() { |
|
|
|
|
UriComponents components = UriComponentsBuilder.fromUriString("/example#").build(); |
|
|
|
|
assertThat(components.getFragment()).isNull(); |
|
|
|
|
assertThat(components.toString()).isEqualTo("/example"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test // SPR-13257
|
|
|
|
|
public void parsesEmptyUri() { |
|
|
|
|
void parsesEmptyUri() { |
|
|
|
|
UriComponents components = UriComponentsBuilder.fromUriString("").build(); |
|
|
|
|
assertThat(components.toString()).isEqualTo(""); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
public void testCloneAndMerge() { |
|
|
|
|
void testCloneAndMerge() { |
|
|
|
|
UriComponentsBuilder builder1 = UriComponentsBuilder.newInstance(); |
|
|
|
|
builder1.scheme("http").host("e1.com").path("/p1").pathSegment("ps1").queryParam("q1").fragment("f1").encode(); |
|
|
|
|
|
|
|
|
|
@ -857,7 +864,7 @@ public class UriComponentsBuilderTests {
@@ -857,7 +864,7 @@ public class UriComponentsBuilderTests {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test // gh-24772
|
|
|
|
|
public void testDeepClone() { |
|
|
|
|
void testDeepClone() { |
|
|
|
|
HashMap<String, Object> vars = new HashMap<>(); |
|
|
|
|
vars.put("ps1", "foo"); |
|
|
|
|
vars.put("ps2", "bar"); |
|
|
|
|
@ -888,7 +895,7 @@ public class UriComponentsBuilderTests {
@@ -888,7 +895,7 @@ public class UriComponentsBuilderTests {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test // SPR-11856
|
|
|
|
|
public void fromHttpRequestForwardedHeader() { |
|
|
|
|
void fromHttpRequestForwardedHeader() { |
|
|
|
|
MockHttpServletRequest request = new MockHttpServletRequest(); |
|
|
|
|
request.addHeader("Forwarded", "proto=https; host=84.198.58.199"); |
|
|
|
|
request.setScheme("http"); |
|
|
|
|
@ -904,7 +911,7 @@ public class UriComponentsBuilderTests {
@@ -904,7 +911,7 @@ public class UriComponentsBuilderTests {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
public void fromHttpRequestForwardedHeaderQuoted() { |
|
|
|
|
void fromHttpRequestForwardedHeaderQuoted() { |
|
|
|
|
MockHttpServletRequest request = new MockHttpServletRequest(); |
|
|
|
|
request.addHeader("Forwarded", "proto=\"https\"; host=\"84.198.58.199\""); |
|
|
|
|
request.setScheme("http"); |
|
|
|
|
@ -920,7 +927,7 @@ public class UriComponentsBuilderTests {
@@ -920,7 +927,7 @@ public class UriComponentsBuilderTests {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
public void fromHttpRequestMultipleForwardedHeader() { |
|
|
|
|
void fromHttpRequestMultipleForwardedHeader() { |
|
|
|
|
MockHttpServletRequest request = new MockHttpServletRequest(); |
|
|
|
|
request.addHeader("Forwarded", "host=84.198.58.199;proto=https"); |
|
|
|
|
request.addHeader("Forwarded", "proto=ftp; host=1.2.3.4"); |
|
|
|
|
@ -937,7 +944,7 @@ public class UriComponentsBuilderTests {
@@ -937,7 +944,7 @@ public class UriComponentsBuilderTests {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
public void fromHttpRequestMultipleForwardedHeaderComma() { |
|
|
|
|
void fromHttpRequestMultipleForwardedHeaderComma() { |
|
|
|
|
MockHttpServletRequest request = new MockHttpServletRequest(); |
|
|
|
|
request.addHeader("Forwarded", "host=84.198.58.199 ;proto=https, proto=ftp; host=1.2.3.4"); |
|
|
|
|
request.setScheme("http"); |
|
|
|
|
@ -953,7 +960,7 @@ public class UriComponentsBuilderTests {
@@ -953,7 +960,7 @@ public class UriComponentsBuilderTests {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
public void fromHttpRequestForwardedHeaderWithHostPortAndWithoutServerPort() { |
|
|
|
|
void fromHttpRequestForwardedHeaderWithHostPortAndWithoutServerPort() { |
|
|
|
|
MockHttpServletRequest request = new MockHttpServletRequest(); |
|
|
|
|
request.addHeader("Forwarded", "proto=https; host=84.198.58.199:9090"); |
|
|
|
|
request.setScheme("http"); |
|
|
|
|
@ -971,7 +978,7 @@ public class UriComponentsBuilderTests {
@@ -971,7 +978,7 @@ public class UriComponentsBuilderTests {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
public void fromHttpRequestForwardedHeaderWithHostPortAndServerPort() { |
|
|
|
|
void fromHttpRequestForwardedHeaderWithHostPortAndServerPort() { |
|
|
|
|
MockHttpServletRequest request = new MockHttpServletRequest(); |
|
|
|
|
request.addHeader("Forwarded", "proto=https; host=84.198.58.199:9090"); |
|
|
|
|
request.setScheme("http"); |
|
|
|
|
@ -990,7 +997,7 @@ public class UriComponentsBuilderTests {
@@ -990,7 +997,7 @@ public class UriComponentsBuilderTests {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
public void fromHttpRequestForwardedHeaderWithoutHostPortAndWithServerPort() { |
|
|
|
|
void fromHttpRequestForwardedHeaderWithoutHostPortAndWithServerPort() { |
|
|
|
|
MockHttpServletRequest request = new MockHttpServletRequest(); |
|
|
|
|
request.addHeader("Forwarded", "proto=https; host=84.198.58.199"); |
|
|
|
|
request.setScheme("http"); |
|
|
|
|
@ -1009,7 +1016,7 @@ public class UriComponentsBuilderTests {
@@ -1009,7 +1016,7 @@ public class UriComponentsBuilderTests {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test // SPR-16262
|
|
|
|
|
public void fromHttpRequestForwardedHeaderWithProtoAndServerPort() { |
|
|
|
|
void fromHttpRequestForwardedHeaderWithProtoAndServerPort() { |
|
|
|
|
MockHttpServletRequest request = new MockHttpServletRequest(); |
|
|
|
|
request.addHeader("Forwarded", "proto=https"); |
|
|
|
|
request.setScheme("http"); |
|
|
|
|
@ -1028,7 +1035,7 @@ public class UriComponentsBuilderTests {
@@ -1028,7 +1035,7 @@ public class UriComponentsBuilderTests {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test // SPR-16364
|
|
|
|
|
public void uriComponentsNotEqualAfterNormalization() { |
|
|
|
|
void uriComponentsNotEqualAfterNormalization() { |
|
|
|
|
UriComponents uri1 = UriComponentsBuilder.fromUriString("http://test.com").build().normalize(); |
|
|
|
|
UriComponents uri2 = UriComponentsBuilder.fromUriString("http://test.com/").build(); |
|
|
|
|
|
|
|
|
|
@ -1038,7 +1045,7 @@ public class UriComponentsBuilderTests {
@@ -1038,7 +1045,7 @@ public class UriComponentsBuilderTests {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test // SPR-17256
|
|
|
|
|
public void uriComponentsWithMergedQueryParams() { |
|
|
|
|
void uriComponentsWithMergedQueryParams() { |
|
|
|
|
String uri = UriComponentsBuilder.fromUriString("http://localhost:8081") |
|
|
|
|
.uriComponents(UriComponentsBuilder.fromUriString("/{path}?sort={sort}").build()) |
|
|
|
|
.queryParam("sort", "another_value").build().toString(); |
|
|
|
|
@ -1047,7 +1054,8 @@ public class UriComponentsBuilderTests {
@@ -1047,7 +1054,8 @@ public class UriComponentsBuilderTests {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test // SPR-17630
|
|
|
|
|
public void toUriStringWithCurlyBraces() { |
|
|
|
|
void toUriStringWithCurlyBraces() { |
|
|
|
|
assertThat(UriComponentsBuilder.fromUriString("/path?q={asa}asa").toUriString()).isEqualTo("/path?q=%7Basa%7Dasa"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|