mirror of
https://github.com/spring-projects/spring-framework
synced 2026-06-08 17:33:33 +00:00
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 a5f81a0)
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2002-2010 the original author or authors.
|
* Copyright 2002-2015 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -23,7 +23,8 @@ import java.io.InputStream;
|
|||||||
* Represents an HTTP input message, consisting of {@linkplain #getHeaders() headers}
|
* Represents an HTTP input message, consisting of {@linkplain #getHeaders() headers}
|
||||||
* and a readable {@linkplain #getBody() body}.
|
* and a readable {@linkplain #getBody() body}.
|
||||||
*
|
*
|
||||||
* <p>Typically implemented by an HTTP request on the server-side, or a response on the client-side.
|
* <p>Typically implemented by an HTTP request handle on the server side,
|
||||||
|
* or an HTTP response handle on the client side.
|
||||||
*
|
*
|
||||||
* @author Arjen Poutsma
|
* @author Arjen Poutsma
|
||||||
* @since 3.0
|
* @since 3.0
|
||||||
@@ -32,7 +33,7 @@ public interface HttpInputMessage extends HttpMessage {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Return the body of the message as an input stream.
|
* Return the body of the message as an input stream.
|
||||||
* @return the input stream body
|
* @return the input stream body (never {@code null})
|
||||||
* @throws IOException in case of I/O Errors
|
* @throws IOException in case of I/O Errors
|
||||||
*/
|
*/
|
||||||
InputStream getBody() throws IOException;
|
InputStream getBody() throws IOException;
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2002-2009 the original author or authors.
|
* Copyright 2002-2015 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -17,8 +17,8 @@
|
|||||||
package org.springframework.http;
|
package org.springframework.http;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents the base interface for HTTP request and response messages. Consists of {@link HttpHeaders}, retrievable
|
* Represents the base interface for HTTP request and response messages.
|
||||||
* via {@link #getHeaders()}.
|
* Consists of {@link HttpHeaders}, retrievable via {@link #getHeaders()}.
|
||||||
*
|
*
|
||||||
* @author Arjen Poutsma
|
* @author Arjen Poutsma
|
||||||
* @since 3.0
|
* @since 3.0
|
||||||
@@ -27,7 +27,7 @@ public interface HttpMessage {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Return the headers of this message.
|
* Return the headers of this message.
|
||||||
* @return a corresponding HttpHeaders object
|
* @return a corresponding HttpHeaders object (never {@code null})
|
||||||
*/
|
*/
|
||||||
HttpHeaders getHeaders();
|
HttpHeaders getHeaders();
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2002-2010 the original author or authors.
|
* Copyright 2002-2015 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -23,7 +23,8 @@ import java.io.OutputStream;
|
|||||||
* Represents an HTTP output message, consisting of {@linkplain #getHeaders() headers}
|
* Represents an HTTP output message, consisting of {@linkplain #getHeaders() headers}
|
||||||
* and a writable {@linkplain #getBody() body}.
|
* and a writable {@linkplain #getBody() body}.
|
||||||
*
|
*
|
||||||
* <p>Typically implemented by an HTTP request on the client-side, or a response on the server-side.
|
* <p>Typically implemented by an HTTP request handle on the client side,
|
||||||
|
* or an HTTP response handle on the server side.
|
||||||
*
|
*
|
||||||
* @author Arjen Poutsma
|
* @author Arjen Poutsma
|
||||||
* @since 3.0
|
* @since 3.0
|
||||||
@@ -32,7 +33,7 @@ public interface HttpOutputMessage extends HttpMessage {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Return the body of the message as an output stream.
|
* Return the body of the message as an output stream.
|
||||||
* @return the output stream body
|
* @return the output stream body (never {@code null})
|
||||||
* @throws IOException in case of I/O Errors
|
* @throws IOException in case of I/O Errors
|
||||||
*/
|
*/
|
||||||
OutputStream getBody() throws IOException;
|
OutputStream getBody() throws IOException;
|
||||||
|
|||||||
+3
-2
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2002-2014 the original author or authors.
|
* Copyright 2002-2015 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -16,6 +16,7 @@
|
|||||||
|
|
||||||
package org.springframework.http.client;
|
package org.springframework.http.client;
|
||||||
|
|
||||||
|
import java.io.ByteArrayInputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
|
|
||||||
@@ -72,7 +73,7 @@ final class HttpComponentsAsyncClientHttpResponse extends AbstractClientHttpResp
|
|||||||
@Override
|
@Override
|
||||||
public InputStream getBody() throws IOException {
|
public InputStream getBody() throws IOException {
|
||||||
HttpEntity entity = this.httpResponse.getEntity();
|
HttpEntity entity = this.httpResponse.getEntity();
|
||||||
return entity != null ? entity.getContent() : null;
|
return (entity != null ? entity.getContent() : new ByteArrayInputStream(new byte[0]));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
+3
-2
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2002-2014 the original author or authors.
|
* Copyright 2002-2015 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -16,6 +16,7 @@
|
|||||||
|
|
||||||
package org.springframework.http.client;
|
package org.springframework.http.client;
|
||||||
|
|
||||||
|
import java.io.ByteArrayInputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
|
|
||||||
@@ -75,7 +76,7 @@ final class HttpComponentsClientHttpResponse extends AbstractClientHttpResponse
|
|||||||
@Override
|
@Override
|
||||||
public InputStream getBody() throws IOException {
|
public InputStream getBody() throws IOException {
|
||||||
HttpEntity entity = this.httpResponse.getEntity();
|
HttpEntity entity = this.httpResponse.getEntity();
|
||||||
return (entity != null ? entity.getContent() : null);
|
return (entity != null ? entity.getContent() : new ByteArrayInputStream(new byte[0]));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
Reference in New Issue
Block a user