Package com.azure.core.http
Class HttpResponse
- java.lang.Object
-
- com.azure.core.http.HttpResponse
-
- All Implemented Interfaces:
Closeable
,AutoCloseable
public abstract class HttpResponse extends Object implements Closeable
The response of anHttpRequest
.
-
-
Constructor Summary
Constructors Modifier Constructor Description protected
HttpResponse(HttpRequest request)
Creates an instance ofHttpResponse
.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description HttpResponse
buffer()
Gets a newresponse
object wrapping this response with its content buffered into memory.void
close()
Closes the response content stream, if any.abstract Flux<ByteBuffer>
getBody()
Get the publisher emitting response content chunks.abstract Mono<byte[]>
getBodyAsByteArray()
Gets the response content as abyte[]
.Mono<InputStream>
getBodyAsInputStream()
Gets the response content as anInputStream
.abstract Mono<String>
getBodyAsString()
Gets the response content as aString
.abstract Mono<String>
getBodyAsString(Charset charset)
Gets the response content as aString
.abstract HttpHeaders
getHeaders()
Get all response headers.abstract String
getHeaderValue(String name)
Lookup a response header with the provided name.HttpRequest
getRequest()
Gets therequest
which resulted in this response.abstract int
getStatusCode()
Get the response status code.
-
-
-
Constructor Detail
-
HttpResponse
protected HttpResponse(HttpRequest request)
Creates an instance ofHttpResponse
.- Parameters:
request
- TheHttpRequest
that resulted in thisHttpResponse
.
-
-
Method Detail
-
getStatusCode
public abstract int getStatusCode()
Get the response status code.- Returns:
- The response status code
-
getHeaderValue
public abstract String getHeaderValue(String name)
Lookup a response header with the provided name.- Parameters:
name
- the name of the header to lookup.- Returns:
- the value of the header, or null if the header doesn't exist in the response.
-
getHeaders
public abstract HttpHeaders getHeaders()
Get all response headers.- Returns:
- the response headers
-
getBody
public abstract Flux<ByteBuffer> getBody()
Get the publisher emitting response content chunks.Returns a stream of the response's body content. Emissions may occur on Reactor threads which should not be blocked. Blocking should be avoided as much as possible/practical in reactive programming but if you do use methods like
block()
on the stream then be sure to usepublishOn
before the blocking call.- Returns:
- The response's content as a stream of
ByteBuffer
.
-
getBodyAsByteArray
public abstract Mono<byte[]> getBodyAsByteArray()
Gets the response content as abyte[]
.- Returns:
- The response content as a
byte[]
.
-
getBodyAsString
public abstract Mono<String> getBodyAsString()
Gets the response content as aString
.By default this method will inspect the response body for containing a byte order mark (BOM) to determine the encoding of the string (UTF-8, UTF-16, etc.). If a BOM isn't found this will default to using UTF-8 as the encoding, if a specific encoding is required use
getBodyAsString(Charset)
.- Returns:
- The response content as a
String
.
-
getBodyAsString
public abstract Mono<String> getBodyAsString(Charset charset)
Gets the response content as aString
.
-
getBodyAsInputStream
public Mono<InputStream> getBodyAsInputStream()
Gets the response content as anInputStream
.- Returns:
- The response content as an
InputStream
.
-
getRequest
public final HttpRequest getRequest()
Gets therequest
which resulted in this response.- Returns:
- The
request
which resulted in this response.
-
buffer
public HttpResponse buffer()
Gets a newresponse
object wrapping this response with its content buffered into memory.- Returns:
- A new
response
with the content buffered.
-
close
public void close()
Closes the response content stream, if any.- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
-
-