Interface HttpResponse
- All Superinterfaces:
AutoCloseable
- All Known Implementing Classes:
ApacheHC5HttpClientResponse, JdkHttpClientResponse
Represents an HTTP response. Must be closed (via
close() or try-with-resources) to release any underlying
connection resources.-
Method Summary
Modifier and TypeMethodDescriptionvoidclose()Closes this response, releasing any underlying connection or stream resources.voiddiscard()Discards the response body, releasing any underlying resources.default voidDiscards the response body and closes this response, releasing the underlying connection.default voidDiscards the response body, silently ignoring anyIOException.Returns anInputStreamover the response body.Returns the first header value for the given name (case-insensitive).default List<HttpHeader> getHeaders(String name) Returns all headers matching the given name (case-insensitive).int
-
Method Details
-
getStatusCode
int getStatusCode()- Returns:
- the HTTP status code.
-
getReasonPhrase
String getReasonPhrase()- Returns:
- the HTTP reason phrase, or an empty string if not available.
-
getHeaders
List<HttpHeader> getHeaders()- Returns:
- all response headers.
-
getHeader
Returns the first header value for the given name (case-insensitive).- Parameters:
name- the header name.- Returns:
- the first matching header value, or
Optional.empty().
-
getHeaders
Returns all headers matching the given name (case-insensitive).- Parameters:
name- the header name.- Returns:
- matching headers, possibly empty.
-
getBodyAsStream
Returns anInputStreamover the response body. For responses with no body (e.g. HTTP 204 No Content, or responses to HEAD requests), implementations must return an empty stream rather thannull.- Returns:
- an
InputStreamover the response body; nevernull - Throws:
IOException- if reading fails.
-
discard
Discards the response body, releasing any underlying resources.- Throws:
IOException- if discarding fails.
-
discardQuietly
default void discardQuietly()Discards the response body, silently ignoring anyIOException. -
close
void close()Closes this response, releasing any underlying connection or stream resources.- Specified by:
closein interfaceAutoCloseable
-
discardAndClose
default void discardAndClose()Discards the response body and closes this response, releasing the underlying connection. AnyIOExceptionthrown bydiscard()is silently ignored;close()is always called.
-