|
|
|
@ -20,9 +20,7 @@ import java.net.URI; |
|
|
|
import java.nio.charset.Charset; |
|
|
|
import java.nio.charset.Charset; |
|
|
|
import java.nio.charset.StandardCharsets; |
|
|
|
import java.nio.charset.StandardCharsets; |
|
|
|
import java.util.ArrayList; |
|
|
|
import java.util.ArrayList; |
|
|
|
import java.util.Arrays; |
|
|
|
|
|
|
|
import java.util.Collection; |
|
|
|
import java.util.Collection; |
|
|
|
import java.util.Collections; |
|
|
|
|
|
|
|
import java.util.HashMap; |
|
|
|
import java.util.HashMap; |
|
|
|
import java.util.LinkedList; |
|
|
|
import java.util.LinkedList; |
|
|
|
import java.util.List; |
|
|
|
import java.util.List; |
|
|
|
@ -34,7 +32,6 @@ import org.springframework.http.HttpHeaders; |
|
|
|
import org.springframework.http.HttpRequest; |
|
|
|
import org.springframework.http.HttpRequest; |
|
|
|
import org.springframework.lang.Nullable; |
|
|
|
import org.springframework.lang.Nullable; |
|
|
|
import org.springframework.util.Assert; |
|
|
|
import org.springframework.util.Assert; |
|
|
|
import org.springframework.util.CollectionUtils; |
|
|
|
|
|
|
|
import org.springframework.util.LinkedMultiValueMap; |
|
|
|
import org.springframework.util.LinkedMultiValueMap; |
|
|
|
import org.springframework.util.MultiValueMap; |
|
|
|
import org.springframework.util.MultiValueMap; |
|
|
|
import org.springframework.util.ObjectUtils; |
|
|
|
import org.springframework.util.ObjectUtils; |
|
|
|
@ -104,6 +101,8 @@ public class UriComponentsBuilder implements UriBuilder, Cloneable { |
|
|
|
|
|
|
|
|
|
|
|
private static final Pattern FORWARDED_PROTO_PATTERN = Pattern.compile("proto=\"?([^;,\"]+)\"?"); |
|
|
|
private static final Pattern FORWARDED_PROTO_PATTERN = Pattern.compile("proto=\"?([^;,\"]+)\"?"); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private static final Object[] EMPTY_VALUES = new Object[0]; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Nullable |
|
|
|
@Nullable |
|
|
|
private String scheme; |
|
|
|
private String scheme; |
|
|
|
@ -700,11 +699,22 @@ public class UriComponentsBuilder implements UriBuilder, Cloneable { |
|
|
|
* @param name the query parameter name |
|
|
|
* @param name the query parameter name |
|
|
|
* @param values the query parameter values |
|
|
|
* @param values the query parameter values |
|
|
|
* @return this UriComponentsBuilder |
|
|
|
* @return this UriComponentsBuilder |
|
|
|
* @see #queryParams(String, Collection) |
|
|
|
* @see #queryParam(String, Collection) |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public UriComponentsBuilder queryParam(String name, Object... values) { |
|
|
|
public UriComponentsBuilder queryParam(String name, Object... values) { |
|
|
|
return queryParams(name, (!ObjectUtils.isEmpty(values) ? Arrays.asList(values) : Collections.emptyList())); |
|
|
|
Assert.notNull(name, "Name must not be null"); |
|
|
|
|
|
|
|
if (!ObjectUtils.isEmpty(values)) { |
|
|
|
|
|
|
|
for (Object value : values) { |
|
|
|
|
|
|
|
String valueAsString = (value != null ? value.toString() : null); |
|
|
|
|
|
|
|
this.queryParams.add(name, valueAsString); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
else { |
|
|
|
|
|
|
|
this.queryParams.add(name, null); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
resetSchemeSpecificPart(); |
|
|
|
|
|
|
|
return this; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
@ -719,19 +729,8 @@ public class UriComponentsBuilder implements UriBuilder, Cloneable { |
|
|
|
* @see #queryParam(String, Object...) |
|
|
|
* @see #queryParam(String, Object...) |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public UriComponentsBuilder queryParams(String name, @Nullable Collection<?> values) { |
|
|
|
public UriComponentsBuilder queryParam(String name, @Nullable Collection<?> values) { |
|
|
|
Assert.notNull(name, "Name must not be null"); |
|
|
|
return queryParam(name, values != null ? values.toArray() : EMPTY_VALUES); |
|
|
|
if (!CollectionUtils.isEmpty(values)) { |
|
|
|
|
|
|
|
for (Object value : values) { |
|
|
|
|
|
|
|
String valueAsString = (value != null ? value.toString() : null); |
|
|
|
|
|
|
|
this.queryParams.add(name, valueAsString); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
else { |
|
|
|
|
|
|
|
this.queryParams.add(name, null); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
resetSchemeSpecificPart(); |
|
|
|
|
|
|
|
return this; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
@ -754,11 +753,17 @@ public class UriComponentsBuilder implements UriBuilder, Cloneable { |
|
|
|
* @param name the query parameter name |
|
|
|
* @param name the query parameter name |
|
|
|
* @param values the query parameter values |
|
|
|
* @param values the query parameter values |
|
|
|
* @return this UriComponentsBuilder |
|
|
|
* @return this UriComponentsBuilder |
|
|
|
* @see #replaceQueryParams(String, Collection) |
|
|
|
* @see #replaceQueryParam(String, Collection) |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public UriComponentsBuilder replaceQueryParam(String name, Object... values) { |
|
|
|
public UriComponentsBuilder replaceQueryParam(String name, Object... values) { |
|
|
|
return replaceQueryParams(name, (!ObjectUtils.isEmpty(values) ? Arrays.asList(values) : Collections.emptyList())); |
|
|
|
Assert.notNull(name, "Name must not be null"); |
|
|
|
|
|
|
|
this.queryParams.remove(name); |
|
|
|
|
|
|
|
if (!ObjectUtils.isEmpty(values)) { |
|
|
|
|
|
|
|
queryParam(name, values); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
resetSchemeSpecificPart(); |
|
|
|
|
|
|
|
return this; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
@ -771,14 +776,8 @@ public class UriComponentsBuilder implements UriBuilder, Cloneable { |
|
|
|
* @since 5.2.0 |
|
|
|
* @since 5.2.0 |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public UriComponentsBuilder replaceQueryParams(String name, @Nullable Collection<?> values) { |
|
|
|
public UriComponentsBuilder replaceQueryParam(String name, @Nullable Collection<?> values) { |
|
|
|
Assert.notNull(name, "Name must not be null"); |
|
|
|
return replaceQueryParam(name, values != null ? values.toArray() : EMPTY_VALUES); |
|
|
|
this.queryParams.remove(name); |
|
|
|
|
|
|
|
if (!CollectionUtils.isEmpty(values)) { |
|
|
|
|
|
|
|
queryParams(name, values); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
resetSchemeSpecificPart(); |
|
|
|
|
|
|
|
return this; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
|