Polishing
This commit is contained in:
parent
08dad4e3ac
commit
b165475eb6
|
|
@ -37,8 +37,8 @@ import org.springframework.util.StringUtils;
|
|||
* is not available in a number of environments (e.g. Android, Java ME), so this is
|
||||
* desirable for portability of Spring's core conversion facility.
|
||||
*
|
||||
* <p>Used to build a TypeDescriptor from a property location.
|
||||
* The built TypeDescriptor can then be used to convert from/to the property type.
|
||||
* <p>Used to build a {@link TypeDescriptor} from a property location. The built
|
||||
* {@code TypeDescriptor} can then be used to convert from/to the property type.
|
||||
*
|
||||
* @author Keith Donald
|
||||
* @author Phillip Webb
|
||||
|
|
|
|||
|
|
@ -748,8 +748,8 @@ public abstract class StringUtils {
|
|||
}
|
||||
|
||||
/**
|
||||
* Parse the given {@code localeString} value into a {@link Locale}.
|
||||
* <p>This is the inverse operation of {@link Locale#toString Locale's toString}.
|
||||
* Parse the given {@code String} value into a {@link Locale}, accepting
|
||||
* the {@link Locale#toString} format as well as BCP 47 language tags.
|
||||
* @param localeValue the locale value: following either {@code Locale's}
|
||||
* {@code toString()} format ("en", "en_UK", etc), also accepting spaces as
|
||||
* separators (as an alternative to underscores), or BCP 47 (e.g. "en-UK")
|
||||
|
|
@ -770,7 +770,7 @@ public abstract class StringUtils {
|
|||
}
|
||||
|
||||
/**
|
||||
* Parse the given {@code localeString} value into a {@link Locale}.
|
||||
* Parse the given {@code String} representation into a {@link Locale}.
|
||||
* <p>This is the inverse operation of {@link Locale#toString Locale's toString}.
|
||||
* @param localeString the locale {@code String}: following {@code Locale's}
|
||||
* {@code toString()} format ("en", "en_UK", etc), also accepting spaces as
|
||||
|
|
|
|||
|
|
@ -60,12 +60,13 @@ public abstract class CorsUtils {
|
|||
if (origin == null) {
|
||||
return true;
|
||||
}
|
||||
UriComponentsBuilder urlBuilder = UriComponentsBuilder.fromHttpRequest(request);
|
||||
UriComponents actualUrl = urlBuilder.build();
|
||||
|
||||
UriComponents actualUrl = UriComponentsBuilder.fromHttpRequest(request).build();
|
||||
String actualHost = actualUrl.getHost();
|
||||
int actualPort = getPort(actualUrl.getScheme(), actualUrl.getPort());
|
||||
Assert.notNull(actualHost, "Actual request host must not be null");
|
||||
Assert.isTrue(actualPort != -1, "Actual request port must not be undefined");
|
||||
|
||||
UriComponents originUrl = UriComponentsBuilder.fromOriginHeader(origin).build();
|
||||
return (actualHost.equals(originUrl.getHost()) &&
|
||||
actualPort == getPort(originUrl.getScheme(), originUrl.getPort()));
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
* Copyright 2002-2018 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.
|
||||
|
|
@ -760,7 +760,7 @@ public class UriComponentsBuilder implements UriBuilder, Cloneable {
|
|||
}
|
||||
}
|
||||
|
||||
if ((this.scheme != null) && ((this.scheme.equals("http") && "80".equals(this.port)) ||
|
||||
if (this.scheme != null && ((this.scheme.equals("http") && "80".equals(this.port)) ||
|
||||
(this.scheme.equals("https") && "443".equals(this.port)))) {
|
||||
port(null);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -711,6 +711,7 @@ public abstract class WebUtils {
|
|||
if (origin == null) {
|
||||
return true;
|
||||
}
|
||||
|
||||
String scheme;
|
||||
String host;
|
||||
int port;
|
||||
|
|
@ -720,12 +721,9 @@ public abstract class WebUtils {
|
|||
scheme = servletRequest.getScheme();
|
||||
host = servletRequest.getServerName();
|
||||
port = servletRequest.getServerPort();
|
||||
|
||||
if(containsForwardedHeaders(servletRequest)) {
|
||||
if (containsForwardedHeaders(servletRequest)) {
|
||||
UriComponents actualUrl = new UriComponentsBuilder()
|
||||
.scheme(scheme)
|
||||
.host(host)
|
||||
.port(port)
|
||||
.scheme(scheme).host(host).port(port)
|
||||
.adaptFromForwardedHeaders(headers)
|
||||
.build();
|
||||
scheme = actualUrl.getScheme();
|
||||
|
|
|
|||
|
|
@ -502,7 +502,7 @@ public class UriComponentsBuilderTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void path() throws URISyntaxException {
|
||||
public void path() {
|
||||
UriComponentsBuilder builder = UriComponentsBuilder.fromPath("/foo/bar");
|
||||
UriComponents result = builder.build();
|
||||
|
||||
|
|
@ -511,7 +511,7 @@ public class UriComponentsBuilderTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void pathSegments() throws URISyntaxException {
|
||||
public void pathSegments() {
|
||||
UriComponentsBuilder builder = UriComponentsBuilder.newInstance();
|
||||
UriComponents result = builder.pathSegment("foo").pathSegment("bar").build();
|
||||
|
||||
|
|
@ -565,7 +565,7 @@ public class UriComponentsBuilderTests {
|
|||
}
|
||||
|
||||
@Test // SPR-12398
|
||||
public void pathWithDuplicateSlashes() throws URISyntaxException {
|
||||
public void pathWithDuplicateSlashes() {
|
||||
UriComponents uriComponents = UriComponentsBuilder.fromPath("/foo/////////bar").build();
|
||||
assertEquals("/foo/bar", uriComponents.getPath());
|
||||
}
|
||||
|
|
@ -601,7 +601,7 @@ public class UriComponentsBuilderTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void queryParams() throws URISyntaxException {
|
||||
public void queryParams() {
|
||||
UriComponentsBuilder builder = UriComponentsBuilder.newInstance();
|
||||
UriComponents result = builder.queryParam("baz", "qux", 42).build();
|
||||
|
||||
|
|
@ -613,7 +613,7 @@ public class UriComponentsBuilderTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void emptyQueryParam() throws URISyntaxException {
|
||||
public void emptyQueryParam() {
|
||||
UriComponentsBuilder builder = UriComponentsBuilder.newInstance();
|
||||
UriComponents result = builder.queryParam("baz").build();
|
||||
|
||||
|
|
@ -736,7 +736,7 @@ public class UriComponentsBuilderTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testClone() throws URISyntaxException {
|
||||
public void testClone() {
|
||||
UriComponentsBuilder builder1 = UriComponentsBuilder.newInstance();
|
||||
builder1.scheme("http").host("e1.com").path("/p1").pathSegment("ps1").queryParam("q1").fragment("f1");
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2015 the original author or authors.
|
||||
* Copyright 2002-2018 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.
|
||||
|
|
@ -16,19 +16,15 @@
|
|||
|
||||
package org.springframework.web.servlet.support;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNull;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.http.HttpRequest;
|
||||
import org.springframework.http.server.ServletServerHttpRequest;
|
||||
import org.springframework.mock.web.test.MockHttpServletRequest;
|
||||
import org.springframework.web.context.request.RequestContextHolder;
|
||||
import org.springframework.web.context.request.ServletRequestAttributes;
|
||||
import org.springframework.web.util.UriComponents;
|
||||
import org.springframework.web.util.UriComponentsBuilder;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
/**
|
||||
* Unit tests for
|
||||
|
|
@ -94,10 +90,7 @@ public class ServletUriComponentsBuilderTests {
|
|||
request.addHeader("X-Forwarded-Proto", "https");
|
||||
request.addHeader("X-Forwarded-Host", "84.198.58.199");
|
||||
request.addHeader("X-Forwarded-Port", "443");
|
||||
|
||||
HttpRequest httpRequest = new ServletServerHttpRequest(request);
|
||||
UriComponents result = UriComponentsBuilder.fromHttpRequest(httpRequest).build();
|
||||
|
||||
UriComponents result = ServletUriComponentsBuilder.fromRequest(request).build();
|
||||
assertEquals("https://84.198.58.199/mvc-showcase", result.toString());
|
||||
}
|
||||
|
||||
|
|
@ -114,7 +107,6 @@ public class ServletUriComponentsBuilderTests {
|
|||
this.request.setRequestURI("/bar");
|
||||
this.request.addHeader("X-Forwarded-Prefix", "/foo");
|
||||
UriComponents result = ServletUriComponentsBuilder.fromRequest(this.request).build();
|
||||
|
||||
assertEquals("http://localhost/foo/bar", result.toUriString());
|
||||
}
|
||||
|
||||
|
|
@ -123,7 +115,6 @@ public class ServletUriComponentsBuilderTests {
|
|||
this.request.setRequestURI("/bar");
|
||||
this.request.addHeader("X-Forwarded-Prefix", "/foo/");
|
||||
UriComponents result = ServletUriComponentsBuilder.fromRequest(this.request).build();
|
||||
|
||||
assertEquals("http://localhost/foo/bar", result.toUriString());
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue