Polishing

This commit is contained in:
Juergen Hoeller
2020-06-06 16:57:28 +02:00
parent b5928977d1
commit 840ae05942
12 changed files with 38 additions and 47 deletions

View File

@@ -18,12 +18,11 @@ package org.springframework.http.codec.json;
import java.lang.annotation.Annotation;
import java.lang.reflect.Type;
import java.nio.charset.StandardCharsets;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.util.Arrays;
import java.util.Collections;
import java.util.EnumSet;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.function.Function;

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2018 the original author or authors.
* Copyright 2002-2020 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.
@@ -111,7 +111,7 @@ class DefaultServerHttpRequestBuilder implements ServerHttpRequest.Builder {
}
@Override
@SuppressWarnings("deprecation")
@Deprecated
public ServerHttpRequest.Builder header(String key, String value) {
this.httpHeaders.add(key, value);
return this;
@@ -215,14 +215,14 @@ class DefaultServerHttpRequestBuilder implements ServerHttpRequest.Builder {
return this.cookies;
}
@Nullable
@Override
@Nullable
public InetSocketAddress getRemoteAddress() {
return this.remoteAddress;
}
@Nullable
@Override
@Nullable
protected SslInfo initSslInfo() {
return this.sslInfo;
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2018 the original author or authors.
* Copyright 2002-2020 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.
@@ -92,6 +92,7 @@ class ReactorServerHttpRequest extends AbstractServerHttpRequest {
}
else {
InetSocketAddress localAddress = request.hostAddress();
Assert.state(localAddress != null, "No host address available");
return new URI(scheme, null, localAddress.getHostString(),
localAddress.getPort(), null, null, null);
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2018 the original author or authors.
* Copyright 2002-2020 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.
@@ -97,12 +97,13 @@ public class ServerHttpRequestDecorator implements ServerHttpRequest {
}
@Override
@Nullable
public InetSocketAddress getRemoteAddress() {
return getDelegate().getRemoteAddress();
}
@Nullable
@Override
@Nullable
public SslInfo getSslInfo() {
return getDelegate().getSslInfo();
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2018 the original author or authors.
* Copyright 2002-2020 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.
@@ -42,6 +42,7 @@ import org.springframework.core.io.buffer.DefaultDataBufferFactory;
import org.springframework.http.HttpCookie;
import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;
import org.springframework.lang.NonNull;
import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
import org.springframework.util.LinkedCaseInsensitiveMap;
@@ -174,10 +175,12 @@ class ServletServerHttpRequest extends AbstractServerHttpRequest {
}
@Override
@NonNull
public InetSocketAddress getRemoteAddress() {
return new InetSocketAddress(this.request.getRemoteHost(), this.request.getRemotePort());
}
@Override
@Nullable
protected SslInfo initSslInfo() {
X509Certificate[] certificates = getX509Certificates();

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2019 the original author or authors.
* Copyright 2002-2020 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.
@@ -101,6 +101,7 @@ class UndertowServerHttpRequest extends AbstractServerHttpRequest {
}
@Override
@Nullable
public InetSocketAddress getRemoteAddress() {
return this.exchange.getSourceAddress();
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2018 the original author or authors.
* Copyright 2002-2020 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.
@@ -52,7 +52,7 @@ import org.springframework.web.util.UriComponentsBuilder;
* @author Rossen Stoyanchev
* @since 5.0
*/
public class MockServerHttpRequest extends AbstractServerHttpRequest {
public final class MockServerHttpRequest extends AbstractServerHttpRequest {
private final HttpMethod httpMethod;
@@ -97,8 +97,8 @@ public class MockServerHttpRequest extends AbstractServerHttpRequest {
return this.remoteAddress;
}
@Nullable
@Override
@Nullable
protected SslInfo initSslInfo() {
return this.sslInfo;
}
@@ -342,9 +342,9 @@ public class MockServerHttpRequest extends AbstractServerHttpRequest {
* @see BodyBuilder#body(String)
*/
MockServerHttpRequest build();
}
/**
* A builder that adds a body to the request.
*/
@@ -383,7 +383,6 @@ public class MockServerHttpRequest extends AbstractServerHttpRequest {
* @return the built request entity
*/
MockServerHttpRequest body(String body);
}
@@ -391,7 +390,6 @@ public class MockServerHttpRequest extends AbstractServerHttpRequest {
private static final DataBufferFactory BUFFER_FACTORY = new DefaultDataBufferFactory();
private final HttpMethod method;
private final URI url;
@@ -411,7 +409,6 @@ public class MockServerHttpRequest extends AbstractServerHttpRequest {
@Nullable
private SslInfo sslInfo;
public DefaultBodyBuilder(HttpMethod method, URI url) {
this.method = method;
this.url = url;
@@ -558,11 +555,9 @@ public class MockServerHttpRequest extends AbstractServerHttpRequest {
private URI getUrlToUse() {
MultiValueMap<String, String> params =
this.queryParamsBuilder.buildAndExpand().encode().getQueryParams();
if (!params.isEmpty()) {
return UriComponentsBuilder.fromUri(this.url).queryParams(params).build(true).toUri();
}
return this.url;
}
}