Interface HttpPlainResponse

All Superinterfaces:
BaseResponse, HttpBaseResponse
All Known Subinterfaces:
HttpResponse, HttpResponse, Response

public interface HttpPlainResponse extends HttpBaseResponse
Represents a response that can manipulate a plain http body (as a single buffer or a flow of chunks).
Author:
Jeoffrey HAEYAERT (jeoffrey.haeyaert at graviteesource.com), GraviteeSource Team
  • Method Details

    • body

      io.reactivex.rxjava3.core.Maybe<Buffer> body()
      Get the current body response as a Maybe. If no body has been set on the response yet, an empty Maybe will returned.

      By getting the body as a Maybe, the current body chunks will be merged together to reconstruct the entire body to provide it in the form of a single Buffer This 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 Maybe observable 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 as body() but returns a Single of Buffer instead.

      If no body response has been set yet, it returns a Single with an empty Buffer. It is a convenient way that avoid checking if the body is set or not prior to manipulate it.

      Returns:
      a Single observable containing the current entire body response or empty an {@link Buffer) if response body has not been set yet.
      See Also:
    • body

      void body(Buffer buffer)
      Set the current body response as a Buffer.

      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 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 single Buffer.

      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 Completable that completes once the body transformation has occurred.
    • chunks

      void chunks(io.reactivex.rxjava3.core.Flowable<Buffer> chunks)
      Set the current response body chunks from a Flowable of Buffer. 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 - the Flowable of 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 as Flowable of Buffer. 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 Flowable containing 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 Completable that completes once the body transformation has occurred on all the chunks.
    • end

      io.reactivex.rxjava3.core.Completable end(HttpBaseExecutionContext ctx)
      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: