Interface ChunkedRestResponseBody

All Known Implementing Classes:
LoggingChunkedRestResponseBody

public interface ChunkedRestResponseBody
The body of a rest response that uses chunked HTTP encoding. Implementations are used to avoid materializing full responses on heap and instead serialize only as much of the response as can be flushed to the network right away.
  • Field Details

    • logger

      static final Logger logger
  • Method Details

    • isDone

      boolean isDone()
      Returns:
      true once this response has been written fully.
    • encodeChunk

      ReleasableBytesReference encodeChunk(int sizeHint, Recycler<org.apache.lucene.util.BytesRef> recycler) throws IOException
      Serializes approximately as many bytes of the response as request by sizeHint to a ReleasableBytesReference that is created from buffers backed by the given recycler.
      Parameters:
      sizeHint - how many bytes to approximately serialize for the given chunk
      recycler - recycler used to acquire buffers
      Returns:
      serialized chunk
      Throws:
      IOException - on serialization failure
    • getResponseContentTypeString

      String getResponseContentTypeString()
      Returns:
      the response Content-Type header value for this response body
    • fromXContent

      static ChunkedRestResponseBody fromXContent(ChunkedToXContent chunkedToXContent, ToXContent.Params params, RestChannel channel) throws IOException
      Create a chunked response body to be written to a specific RestChannel from a ChunkedToXContent.
      Parameters:
      chunkedToXContent - chunked x-content instance to serialize
      params - parameters to use for serialization
      channel - channel the response will be written to
      Returns:
      chunked rest response body
      Throws:
      IOException
    • fromTextChunks

      static ChunkedRestResponseBody fromTextChunks(String contentType, Iterator<CheckedConsumer<Writer,IOException>> chunkIterator)
      Create a chunked response body to be written to a specific RestChannel from a stream of text chunks, each represented as a consumer of a Writer.