Skip to content

Commit a5f81a0

Browse files
committed
Clarified that getBody() never returns null
As the only place that historically differed, HttpComponents(Async)ClientHttpResponse returns an empty stream instead of null now. Issue: SPR-13563
1 parent 66177df commit a5f81a0

File tree

5 files changed

+17
-13
lines changed

5 files changed

+17
-13
lines changed

spring-web/src/main/java/org/springframework/http/HttpInputMessage.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2010 the original author or authors.
2+
* Copyright 2002-2015 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.
@@ -23,7 +23,8 @@
2323
* Represents an HTTP input message, consisting of {@linkplain #getHeaders() headers}
2424
* and a readable {@linkplain #getBody() body}.
2525
*
26-
* <p>Typically implemented by an HTTP request on the server-side, or a response on the client-side.
26+
* <p>Typically implemented by an HTTP request handle on the server side,
27+
* or an HTTP response handle on the client side.
2728
*
2829
* @author Arjen Poutsma
2930
* @since 3.0
@@ -32,7 +33,7 @@ public interface HttpInputMessage extends HttpMessage {
3233

3334
/**
3435
* Return the body of the message as an input stream.
35-
* @return the input stream body
36+
* @return the input stream body (never {@code null})
3637
* @throws IOException in case of I/O Errors
3738
*/
3839
InputStream getBody() throws IOException;

spring-web/src/main/java/org/springframework/http/HttpMessage.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2009 the original author or authors.
2+
* Copyright 2002-2015 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.
@@ -17,8 +17,8 @@
1717
package org.springframework.http;
1818

1919
/**
20-
* Represents the base interface for HTTP request and response messages. Consists of {@link HttpHeaders}, retrievable
21-
* via {@link #getHeaders()}.
20+
* Represents the base interface for HTTP request and response messages.
21+
* Consists of {@link HttpHeaders}, retrievable via {@link #getHeaders()}.
2222
*
2323
* @author Arjen Poutsma
2424
* @since 3.0
@@ -27,7 +27,7 @@ public interface HttpMessage {
2727

2828
/**
2929
* Return the headers of this message.
30-
* @return a corresponding HttpHeaders object
30+
* @return a corresponding HttpHeaders object (never {@code null})
3131
*/
3232
HttpHeaders getHeaders();
3333

spring-web/src/main/java/org/springframework/http/HttpOutputMessage.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2010 the original author or authors.
2+
* Copyright 2002-2015 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.
@@ -23,7 +23,8 @@
2323
* Represents an HTTP output message, consisting of {@linkplain #getHeaders() headers}
2424
* and a writable {@linkplain #getBody() body}.
2525
*
26-
* <p>Typically implemented by an HTTP request on the client-side, or a response on the server-side.
26+
* <p>Typically implemented by an HTTP request handle on the client side,
27+
* or an HTTP response handle on the server side.
2728
*
2829
* @author Arjen Poutsma
2930
* @since 3.0
@@ -32,7 +33,7 @@ public interface HttpOutputMessage extends HttpMessage {
3233

3334
/**
3435
* Return the body of the message as an output stream.
35-
* @return the output stream body
36+
* @return the output stream body (never {@code null})
3637
* @throws IOException in case of I/O Errors
3738
*/
3839
OutputStream getBody() throws IOException;

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

Lines changed: 3 additions & 2 deletions
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-2015 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.
@@ -24,6 +24,7 @@
2424
import org.apache.http.HttpResponse;
2525

2626
import org.springframework.http.HttpHeaders;
27+
import org.springframework.util.StreamUtils;
2728

2829
/**
2930
* {@link ClientHttpResponse} implementation that uses
@@ -72,7 +73,7 @@ public HttpHeaders getHeaders() {
7273
@Override
7374
public InputStream getBody() throws IOException {
7475
HttpEntity entity = this.httpResponse.getEntity();
75-
return entity != null ? entity.getContent() : null;
76+
return (entity != null ? entity.getContent() : StreamUtils.emptyInput());
7677
}
7778

7879
@Override

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import org.apache.http.util.EntityUtils;
2727

2828
import org.springframework.http.HttpHeaders;
29+
import org.springframework.util.StreamUtils;
2930

3031
/**
3132
* {@link org.springframework.http.client.ClientHttpResponse} implementation that uses
@@ -76,7 +77,7 @@ public HttpHeaders getHeaders() {
7677
@Override
7778
public InputStream getBody() throws IOException {
7879
HttpEntity entity = this.httpResponse.getEntity();
79-
return (entity != null ? entity.getContent() : null);
80+
return (entity != null ? entity.getContent() : StreamUtils.emptyInput());
8081
}
8182

8283
@Override

0 commit comments

Comments
 (0)