Skip to content

Commit 570851e

Browse files
committed
Consistent headers.getContentLength() checks
(cherry picked from commit 7f438dc)
1 parent e366746 commit 570851e

File tree

4 files changed

+6
-6
lines changed

4 files changed

+6
-6
lines changed

Diff for: spring-web/src/main/java/org/springframework/http/client/AbstractBufferingAsyncClientHttpRequest.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2014 the original author or authors.
2+
* Copyright 2002-2016 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -43,7 +43,7 @@ protected OutputStream getBodyInternal(HttpHeaders headers) throws IOException {
4343
@Override
4444
protected ListenableFuture<ClientHttpResponse> executeInternal(HttpHeaders headers) throws IOException {
4545
byte[] bytes = this.bufferedOutput.toByteArray();
46-
if (headers.getContentLength() == -1) {
46+
if (headers.getContentLength() < 0) {
4747
headers.setContentLength(bytes.length);
4848
}
4949
ListenableFuture<ClientHttpResponse> result = executeInternal(headers, bytes);

Diff for: spring-web/src/main/java/org/springframework/http/client/AbstractBufferingClientHttpRequest.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2014 the original author or authors.
2+
* Copyright 2002-2016 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -42,7 +42,7 @@ protected OutputStream getBodyInternal(HttpHeaders headers) throws IOException {
4242
@Override
4343
protected ClientHttpResponse executeInternal(HttpHeaders headers) throws IOException {
4444
byte[] bytes = this.bufferedOutput.toByteArray();
45-
if (headers.getContentLength() == -1) {
45+
if (headers.getContentLength() < 0) {
4646
headers.setContentLength(bytes.length);
4747
}
4848
ClientHttpResponse result = executeInternal(headers, bytes);

Diff for: spring-web/src/main/java/org/springframework/http/server/ServletServerHttpRequest.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ public HttpHeaders getHeaders() {
132132
this.headers.setContentType(newContentType);
133133
}
134134
}
135-
if (this.headers.getContentLength() == -1) {
135+
if (this.headers.getContentLength() < 0) {
136136
int requestContentLength = this.servletRequest.getContentLength();
137137
if (requestContentLength != -1) {
138138
this.headers.setContentLength(requestContentLength);

Diff for: spring-web/src/main/java/org/springframework/web/client/RestTemplate.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -780,7 +780,7 @@ public void doWithRequest(ClientHttpRequest httpRequest) throws IOException {
780780
if (!requestHeaders.isEmpty()) {
781781
httpHeaders.putAll(requestHeaders);
782782
}
783-
if (httpHeaders.getContentLength() == -1) {
783+
if (httpHeaders.getContentLength() < 0) {
784784
httpHeaders.setContentLength(0L);
785785
}
786786
}

0 commit comments

Comments
 (0)