Skip to content

Commit cf75a09

Browse files
committed
Polishing
1 parent 45c20e3 commit cf75a09

File tree

7 files changed

+44
-45
lines changed

7 files changed

+44
-45
lines changed

spring-r2dbc/src/main/java/org/springframework/r2dbc/core/BeanPropertyRowMapper.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,7 @@ private <R extends Readable> T mapForReadable(R readable, List<? extends Readabl
330330
bw.setPropertyValue(pd.getName(), value);
331331
}
332332
catch (TypeMismatchException ex) {
333-
if (value == null && this.primitivesDefaultedForNullValue) {
333+
if (value == null && isPrimitivesDefaultedForNullValue()) {
334334
if (logger.isDebugEnabled()) {
335335
String propertyType = ClassUtils.getQualifiedName(pd.getPropertyType());
336336
//here too, we miss the rowNumber information

spring-web/src/main/java/org/springframework/http/client/JdkClientHttpRequest.java

+25-26
Original file line numberDiff line numberDiff line change
@@ -51,25 +51,6 @@ class JdkClientHttpRequest extends AbstractStreamingClientHttpRequest {
5151

5252
private static final Set<String> DISALLOWED_HEADERS = disallowedHeaders();
5353

54-
/**
55-
* By default, {@link HttpRequest} does not allow {@code Connection},
56-
* {@code Content-Length}, {@code Expect}, {@code Host}, or {@code Upgrade}
57-
* headers to be set, but this can be overriden with the
58-
* {@code jdk.httpclient.allowRestrictedHeaders} system property.
59-
* @see jdk.internal.net.http.common.Utils#getDisallowedHeaders()
60-
*/
61-
private static Set<String> disallowedHeaders() {
62-
TreeSet<String> headers = new TreeSet<>(String.CASE_INSENSITIVE_ORDER);
63-
headers.addAll(Set.of("connection", "content-length", "expect", "host", "upgrade"));
64-
65-
String headersToAllow = System.getProperty("jdk.httpclient.allowRestrictedHeaders");
66-
if (headersToAllow != null) {
67-
Set<String> toAllow = StringUtils.commaDelimitedListToSet(headersToAllow);
68-
headers.removeAll(toAllow);
69-
}
70-
return Collections.unmodifiableSet(headers);
71-
}
72-
7354

7455
private final HttpClient httpClient;
7556

@@ -85,13 +66,15 @@ private static Set<String> disallowedHeaders() {
8566

8667
public JdkClientHttpRequest(HttpClient httpClient, URI uri, HttpMethod method, Executor executor,
8768
@Nullable Duration readTimeout) {
69+
8870
this.httpClient = httpClient;
8971
this.uri = uri;
9072
this.method = method;
9173
this.executor = executor;
9274
this.timeout = readTimeout;
9375
}
9476

77+
9578
@Override
9679
public HttpMethod getMethod() {
9780
return this.method;
@@ -107,7 +90,8 @@ public URI getURI() {
10790
protected ClientHttpResponse executeInternal(HttpHeaders headers, @Nullable Body body) throws IOException {
10891
try {
10992
HttpRequest request = buildRequest(headers, body);
110-
HttpResponse<InputStream> response = this.httpClient.send(request, HttpResponse.BodyHandlers.ofInputStream());
93+
HttpResponse<InputStream> response =
94+
this.httpClient.send(request, HttpResponse.BodyHandlers.ofInputStream());
11195
return new JdkClientHttpResponse(response);
11296
}
11397
catch (UncheckedIOException ex) {
@@ -121,9 +105,7 @@ protected ClientHttpResponse executeInternal(HttpHeaders headers, @Nullable Body
121105

122106

123107
private HttpRequest buildRequest(HttpHeaders headers, @Nullable Body body) {
124-
HttpRequest.Builder builder = HttpRequest.newBuilder()
125-
.uri(this.uri);
126-
108+
HttpRequest.Builder builder = HttpRequest.newBuilder().uri(this.uri);
127109
if (this.timeout != null) {
128110
builder.timeout(this.timeout);
129111
}
@@ -144,8 +126,7 @@ private HttpRequest.BodyPublisher bodyPublisher(HttpHeaders headers, @Nullable B
144126
if (body != null) {
145127
Flow.Publisher<ByteBuffer> outputStreamPublisher = OutputStreamPublisher.create(
146128
outputStream -> body.writeTo(StreamUtils.nonClosing(outputStream)),
147-
BYTE_MAPPER,
148-
this.executor);
129+
BYTE_MAPPER, this.executor);
149130

150131
long contentLength = headers.getContentLength();
151132
if (contentLength != -1) {
@@ -160,6 +141,25 @@ private HttpRequest.BodyPublisher bodyPublisher(HttpHeaders headers, @Nullable B
160141
}
161142
}
162143

144+
/**
145+
* By default, {@link HttpRequest} does not allow {@code Connection},
146+
* {@code Content-Length}, {@code Expect}, {@code Host}, or {@code Upgrade}
147+
* headers to be set, but this can be overriden with the
148+
* {@code jdk.httpclient.allowRestrictedHeaders} system property.
149+
* @see jdk.internal.net.http.common.Utils#getDisallowedHeaders()
150+
*/
151+
private static Set<String> disallowedHeaders() {
152+
TreeSet<String> headers = new TreeSet<>(String.CASE_INSENSITIVE_ORDER);
153+
headers.addAll(Set.of("connection", "content-length", "expect", "host", "upgrade"));
154+
155+
String headersToAllow = System.getProperty("jdk.httpclient.allowRestrictedHeaders");
156+
if (headersToAllow != null) {
157+
Set<String> toAllow = StringUtils.commaDelimitedListToSet(headersToAllow);
158+
headers.removeAll(toAllow);
159+
}
160+
return Collections.unmodifiableSet(headers);
161+
}
162+
163163

164164
private static final class ByteBufferMapper implements OutputStreamPublisher.ByteMapper<ByteBuffer> {
165165

@@ -178,7 +178,6 @@ public ByteBuffer map(byte[] b, int off, int len) {
178178
byteBuffer.flip();
179179
return byteBuffer;
180180
}
181-
182181
}
183182

184183
}

spring-web/src/main/java/org/springframework/http/client/JdkClientHttpRequestFactory.java

-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
import org.springframework.lang.Nullable;
2828
import org.springframework.util.Assert;
2929

30-
3130
/**
3231
* {@link ClientHttpRequestFactory} implementation based on the Java
3332
* {@link HttpClient}.

spring-web/src/main/java/org/springframework/http/client/JdkClientHttpResponse.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public JdkClientHttpResponse(HttpResponse<InputStream> response) {
5252
this.response = response;
5353
this.headers = adaptHeaders(response);
5454
InputStream inputStream = response.body();
55-
this.body = (inputStream != null) ? inputStream : InputStream.nullInputStream();
55+
this.body = (inputStream != null ? inputStream : InputStream.nullInputStream());
5656
}
5757

5858
private static HttpHeaders adaptHeaders(HttpResponse<?> response) {
@@ -103,4 +103,5 @@ public void close() {
103103
catch (IOException ignored) {
104104
}
105105
}
106+
106107
}

spring-web/src/main/java/org/springframework/http/client/ReactorNettyClientRequest.java

+1-2
Original file line numberDiff line numberDiff line change
@@ -141,12 +141,10 @@ private static final class ByteBufMapper implements OutputStreamPublisher.ByteMa
141141

142142
private final ByteBufAllocator allocator;
143143

144-
145144
public ByteBufMapper(ByteBufAllocator allocator) {
146145
this.allocator = allocator;
147146
}
148147

149-
150148
@Override
151149
public ByteBuf map(int b) {
152150
ByteBuf byteBuf = this.allocator.buffer(1);
@@ -161,4 +159,5 @@ public ByteBuf map(byte[] b, int off, int len) {
161159
return byteBuf;
162160
}
163161
}
162+
164163
}

spring-web/src/main/java/org/springframework/http/client/ReactorNettyClientRequestFactory.java

+2-3
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,11 @@ public class ReactorNettyClientRequestFactory implements ClientHttpRequestFactor
3636

3737
private final HttpClient httpClient;
3838

39-
4039
private Duration exchangeTimeout = Duration.ofSeconds(5);
4140

4241
private Duration readTimeout = Duration.ofSeconds(10);
4342

4443

45-
4644
/**
4745
* Create a new instance of the {@code ReactorNettyClientRequestFactory}
4846
* with a default {@link HttpClient} that has compression enabled.
@@ -61,6 +59,7 @@ public ReactorNettyClientRequestFactory(HttpClient httpClient) {
6159
this.httpClient = httpClient;
6260
}
6361

62+
6463
/**
6564
* Set the underlying connect timeout in milliseconds.
6665
* A value of 0 specifies an infinite timeout.
@@ -125,9 +124,9 @@ public void setExchangeTimeout(Duration exchangeTimeout) {
125124
}
126125

127126

128-
129127
@Override
130128
public ClientHttpRequest createRequest(URI uri, HttpMethod httpMethod) throws IOException {
131129
return new ReactorNettyClientRequest(this.httpClient, uri, httpMethod, this.exchangeTimeout, this.readTimeout);
132130
}
131+
133132
}

spring-web/src/main/java/org/springframework/http/client/ReactorNettyClientResponse.java

+13-11
Original file line numberDiff line numberDiff line change
@@ -48,14 +48,14 @@ final class ReactorNettyClientResponse implements ClientHttpResponse {
4848
private volatile InputStream body;
4949

5050

51-
5251
public ReactorNettyClientResponse(HttpClientResponse response, Connection connection, Duration readTimeout) {
5352
this.response = response;
5453
this.connection = connection;
5554
this.readTimeout = readTimeout;
5655
this.headers = HttpHeaders.readOnlyHttpHeaders(new Netty4HeadersAdapter(response.responseHeaders()));
5756
}
5857

58+
5959
@Override
6060
public HttpStatusCode getStatusCode() {
6161
return HttpStatusCode.valueOf(this.response.status().code());
@@ -73,21 +73,23 @@ public HttpHeaders getHeaders() {
7373

7474
@Override
7575
public InputStream getBody() throws IOException {
76-
if (this.body == null) {
77-
InputStream body = this.connection.inbound().receive()
78-
.aggregate().asInputStream().block(this.readTimeout);
79-
if (body != null) {
80-
this.body = body;
81-
}
82-
else {
83-
throw new IOException("Could not receive body");
84-
}
76+
InputStream body = this.body;
77+
if (body != null) {
78+
return body;
8579
}
86-
return this.body;
80+
81+
body = this.connection.inbound().receive()
82+
.aggregate().asInputStream().block(this.readTimeout);
83+
if (body == null) {
84+
throw new IOException("Could not receive body");
85+
}
86+
this.body = body;
87+
return body;
8788
}
8889

8990
@Override
9091
public void close() {
9192
this.connection.dispose();
9293
}
94+
9395
}

0 commit comments

Comments
 (0)