Skip to content

Commit 8a82259

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 (cherry picked from commit ca60d79)
1 parent 6c138d3 commit 8a82259

File tree

4 files changed

+15
-12
lines changed

4 files changed

+15
-12
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/HttpComponentsClientHttpResponse.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2012 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.
@@ -16,6 +16,7 @@
1616

1717
package org.springframework.http.client;
1818

19+
import java.io.ByteArrayInputStream;
1920
import java.io.IOException;
2021
import java.io.InputStream;
2122

@@ -69,7 +70,7 @@ public HttpHeaders getHeaders() {
6970

7071
public InputStream getBody() throws IOException {
7172
HttpEntity entity = this.httpResponse.getEntity();
72-
return entity != null ? entity.getContent() : null;
73+
return (entity != null ? entity.getContent() : new ByteArrayInputStream(new byte[0]));
7374
}
7475

7576
public void close() {

0 commit comments

Comments
 (0)