public abstract class HttpResponse extends Object implements Closeable
HttpRequest
.Modifier | Constructor and Description |
---|---|
protected |
HttpResponse(HttpRequest request) |
Modifier and Type | Method and Description |
---|---|
HttpResponse |
buffer()
Get a new Response object wrapping this response with it's 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()
Get the response content as a byte[].
|
abstract Mono<String> |
getBodyAsString()
Get the response content as a string.
|
abstract Mono<String> |
getBodyAsString(Charset charset)
Get the response content as a string.
|
abstract HttpHeaders |
getHeaders()
Get all response headers.
|
abstract String |
getHeaderValue(String name)
Lookup a response header with the provided name.
|
HttpRequest |
getRequest()
Get the request which resulted in this response.
|
abstract int |
getStatusCode()
Get the response status code.
|
protected HttpResponse(HttpRequest request)
public abstract int getStatusCode()
public abstract String getHeaderValue(String name)
name
- the name of the header to lookup.public abstract HttpHeaders getHeaders()
public abstract Flux<ByteBuffer> getBody()
Returns a stream of the response's body content. Emissions may occur on the
Netty EventLoop threads which are shared across channels and should not be
blocked. Blocking should be avoided as much as possible/practical in reactive
programming but if you do use methods like blockingSubscribe
or blockingGet
on the stream then be sure to use subscribeOn
and observeOn
before the blocking call. For example:
response.body()
.map(bb -> bb.limit())
.reduce((x,y) -> x + y)
.subscribeOn(Schedulers.io())
.observeOn(Schedulers.io())
;
The above code is a simplistic example and would probably run fine without the `subscribeOn` and `observeOn` but should be considered a template for more complex situations.
ByteBuffer
.public abstract Mono<byte[]> getBodyAsByteArray()
public abstract Mono<String> getBodyAsString()
public abstract Mono<String> getBodyAsString(Charset charset)
charset
- the charset to use as encodingpublic final HttpRequest getRequest()
public HttpResponse buffer()
public void close()
close
in interface Closeable
close
in interface AutoCloseable
Copyright © 2021 Microsoft Corporation. All rights reserved.