Interface Response
-
public interface Response
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description io.reactivex.Maybe<Buffer>body()Get the current body response as aMaybe.voidbody(Buffer buffer)Set the current body response as aBuffer.io.reactivex.Single<Buffer>bodyOrEmpty()io.reactivex.Flowable<Buffer>chunks()Get the current response body chunks asFlowableofBuffer.voidchunks(io.reactivex.Flowable<Buffer> chunks)Set the current response body chunks from aFlowableofBuffer.io.reactivex.Completableend()End the response.booleanended()Indicates if the response is ended or not.HttpHeadersheaders()io.reactivex.CompletableonBody(io.reactivex.MaybeTransformer<Buffer,Buffer> onBody)Applies a transformation on the complete body given as a singleBuffer.io.reactivex.CompletableonChunk(io.reactivex.FlowableTransformer<Buffer,Buffer> onChunk)Applies a transformation on each body chunks and completes when all the chunks have been processed.Stringreason()Responsereason(String message)intstatus()Responsestatus(int statusCode)HttpHeaderstrailers()
-
-
-
Method Detail
-
status
Response status(int statusCode)
-
status
int status()
-
reason
String reason()
- Returns:
- Reason-Phrase is intended to give a short textual description of the Status-Code.
-
headers
HttpHeaders headers()
- Returns:
- the headers in the response.
-
trailers
HttpHeaders trailers()
-
ended
boolean ended()
Indicates if the response is ended or not. Ended response means the response has been fully push to the client, including response body.- Returns:
trueif the response has been fully pushed to the client,falseelse.
-
body
io.reactivex.Maybe<Buffer> body()
Get the current body response as aMaybe. If no body has not been set on the response yet, an emptyMaybewill returned. By getting the body as aMaybe, the current body chunks will be merged together to reconstruct the entire body in provide it in the form of a singleBufferThis is useful when the entire body is required to apply some transformation or any manipulation. WARN: beware that the entire body content will be loaded in memory. You should not keep a direct reference on the body chunks as they could be overridden by others at anytime.- Returns:
- a
Maybeobservable containing the current entire body response or empty if response body as not been set yet. - See Also:
bodyOrEmpty()
-
bodyOrEmpty
io.reactivex.Single<Buffer> bodyOrEmpty()
Same asbody()but returns aSingleofBufferinstead. If no body response as been set yet, it returns aSinglewith an emptyBuffer. It is a convenient way that avoid checking if the body is set or not prior to manipulate it.- Returns:
- a
Singleobservable containing the current entire body response or empty an {@link Buffer) if response body as not been set yet. - See Also:
body()
-
body
void body(Buffer buffer)
Set the current body response as aBuffer. This is useful when you want to replace the current body response with a specific content that doesn't come from a reactive chain, ex:response.body(Buffer.buffer("My custom content");WARN: replacing the request body will "drain" the previous request that was in place but occurs outside the reactive chain. You should consider usingonBody(MaybeTransformer)to change the body during the chain execution.- See Also:
onBody(MaybeTransformer),chunks(Flowable)
-
onBody
io.reactivex.Completable onBody(io.reactivex.MaybeTransformer<Buffer,Buffer> onBody)
Applies a transformation on the complete body given as a singleBuffer. Ex:response.onBody(body -> body.map(buffer ->Buffer.buffer(buffer.toString().toUpperCase())));IMPORTANT: applying a transformation on the body content loads the whole body in memory. It's up to the consumer to make sure it is safe to do that without consuming too much memory.- Parameters:
onBody- the transformation that will be applied on the body.- Returns:
- a
Completablethat completes once the body transformation has occurred.
-
chunks
void chunks(io.reactivex.Flowable<Buffer> chunks)
Set the current response body chunks from aFlowableofBuffer. This is useful to directly pump the upstream chunks to the downstream without having to load all the chunks in memory.
WARN: replacing the response body will "drain" the previous response that was in place.- Parameters:
chunks- the flowable of chunks representing the response to push back to the downstream.- See Also:
body()
-
chunks
io.reactivex.Flowable<Buffer> chunks()
Get the current response body chunks asFlowableofBuffer. This is useful when you want to manipulate the entire body without having to load it in memory. WARN: you should not keep a direct reference on the body chunks as they could be overridden by others at anytime.- Returns:
- a
Flowablecontaining the current body response chunks.
-
onChunk
io.reactivex.Completable onChunk(io.reactivex.FlowableTransformer<Buffer,Buffer> onChunk)
Applies a transformation on each body chunks and completes when all the chunks have been processed. Ex:response.onChunk(chunks -> chunks.map(buffer -> Buffer.buffer(buffer.toString().toUpperCase())));IMPORTANT: applying a transformation on the body chunks loads the whole body in memory. It's up to the consumer to make sure it is safe to do that without consuming too much memory. IMPORTANT: applying a transformation on chunks completes when all chunks have been transformed. If used in a policy chain, it means that the next policy will start once all chunks have been transformed- Parameters:
onChunk- the transformer that will be applied.- Returns:
- a
Completablethat completes once the body transformation has occurred on all the chunks.
-
end
io.reactivex.Completable end()
End the response.- Returns:
- an observable that can be easily chained.
-
-