Interface HttpPlainResponse
- All Superinterfaces:
BaseResponse,HttpBaseResponse
- All Known Subinterfaces:
HttpResponse,HttpResponse,Response
- Author:
- Jeoffrey HAEYAERT (jeoffrey.haeyaert at graviteesource.com), GraviteeSource Team
-
Method Summary
Modifier and TypeMethodDescriptionio.reactivex.rxjava3.core.Maybe<Buffer>body()Get the current body response as aMaybe.voidSet the current body response as aBuffer.io.reactivex.rxjava3.core.Single<Buffer>io.reactivex.rxjava3.core.Flowable<Buffer>chunks()Get the current response body chunks asFlowableofBuffer.voidSet the current response body chunks from aFlowableofBuffer.voidcontentLength(long length) Set the `Content-Length` header to the response.io.reactivex.rxjava3.core.CompletableEnd the response.io.reactivex.rxjava3.core.CompletableApplies a transformation on the complete body given as a singleBuffer.io.reactivex.rxjava3.core.CompletableApplies a transformation on each body chunks and completes when all the chunks have been processed.Methods inherited from interface io.gravitee.gateway.reactive.api.context.http.HttpBaseResponse
ended, headers, isStatus1xx, isStatus2xx, isStatus3xx, isStatus4xx, isStatus5xx, reason, reason, status, status, trailers
-
Method Details
-
body
io.reactivex.rxjava3.core.Maybe<Buffer> body()Get the current body response as aMaybe. If no body has been set on the response yet, an emptyMaybewill returned.By getting the body as a
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.Maybe, the current body chunks will be merged together to reconstruct the entire body to provide it in the form of a singleBufferThis is useful when the entire body is required to apply some transformation or any manipulation.- Returns:
- a
Maybeobservable containing the current entire body response or empty if response body has not been set yet. - See Also:
-
bodyOrEmpty
io.reactivex.rxjava3.core.Single<Buffer> bodyOrEmpty()Same asbody()but returns aSingleofBufferinstead.If no body response has been set yet, it returns a
Singlewith 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 has not been set yet. - See Also:
-
body
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:
WARN:response.body(Buffer.buffer("My custom content");- replacing the request body will NOT "drain" the previous request that was in place.
- You MUST ensure to consume the previous body by yourself when using it.
- You SHOULD consider using
onBody(MaybeTransformer)to change the body during the chain execution.
- See Also:
-
onBody
io.reactivex.rxjava3.core.Completable onBody(io.reactivex.rxjava3.core.MaybeTransformer<Buffer, Buffer> onBody) Applies a transformation on the complete body given as a singleBuffer.Ex:
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.response.onBody(body -> body.map(buffer ->Buffer.buffer(buffer.toString().toUpperCase())));- Parameters:
onBody- the transformation that will be applied on the body.- Returns:
- a
Completablethat completes once the body transformation has occurred.
-
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 chunks will NOT "drain" the previous response that was in place.
- You MUST ensure to consume the previous chunks by yourself when using it.
- You SHOULD consider using
onChunks(FlowableTransformer)to change the chunks during the chain execution.
- Parameters:
chunks- theFlowableof chunks representing the response to push back to the downstream.- See Also:
-
chunks
io.reactivex.rxjava3.core.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.
-
onChunks
io.reactivex.rxjava3.core.Completable onChunks(io.reactivex.rxjava3.core.FlowableTransformer<Buffer, Buffer> onChunks) Applies a transformation on each body chunks and completes when all the chunks have been processed. Ex:response.onChunks(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:
onChunks- the transformer that will be applied.- Returns:
- a
Completablethat completes once the body transformation has occurred on all the chunks.
-
end
End the response.- Returns:
- an observable that can be easily chained.
-
contentLength
void contentLength(long length) Set the `Content-Length` header to the response.WARN: any existing `Transfer-Encoding` header will be removed.
- Parameters:
length- The value of the `Content-Length` header- See Also:
-