Class BufferedResponseHandler

All Implemented Interfaces:
Handler, Handler.Container, Handler.Singleton, Request.Handler, org.eclipse.jetty.util.component.Container, org.eclipse.jetty.util.component.Destroyable, org.eclipse.jetty.util.component.Dumpable, org.eclipse.jetty.util.component.Dumpable.DumpableContainer, org.eclipse.jetty.util.component.LifeCycle, org.eclipse.jetty.util.thread.Invocable

public class BufferedResponseHandler extends ConditionalHandler.Abstract

A Handler that can apply a mechanism to buffer the entire response content until the output is closed. This allows the commit to be delayed until the response is complete and thus headers and response status can be changed while writing the body.

Note that the decision to buffer is influenced by the headers and status at the first write, and thus subsequent changes to those headers will not influence the decision to buffer or not.

Note also that the size of the buffer can be controlled by setting the BUFFER_SIZE_ATTRIBUTE_NAME request attribute to an integer; in the absence of such header, the HttpConfiguration.getOutputBufferSize() config setting is used, while the maximum aggregation size can be controlled by setting the MAX_AGGREGATION_SIZE_ATTRIBUTE_NAME request attribute to an integer, in the absence of such header, the HttpConfiguration.getOutputAggregationSize() config setting is used.

  • Field Details

    • BUFFER_SIZE_ATTRIBUTE_NAME

      public static final String BUFFER_SIZE_ATTRIBUTE_NAME
      The name of the request attribute used to control the buffer size of a particular request.
    • MAX_AGGREGATION_SIZE_ATTRIBUTE_NAME

      public static final String MAX_AGGREGATION_SIZE_ATTRIBUTE_NAME
      The name of the request attribute used to control the max aggregation size of a particular request.
  • Constructor Details

    • BufferedResponseHandler

      public BufferedResponseHandler()
    • BufferedResponseHandler

      public BufferedResponseHandler(Handler handler)
  • Method Details

    • includeMimeType

      public void includeMimeType(String... mimeTypes)
    • excludeMimeType

      public void excludeMimeType(String... mimeTypes)
    • isMimeTypeBufferable

      protected boolean isMimeTypeBufferable(String mimetype)
    • shouldBuffer

      protected boolean shouldBuffer(Response response, boolean last)
    • onConditionsMet

      public boolean onConditionsMet(Request request, Response response, org.eclipse.jetty.util.Callback callback) throws Exception
      Description copied from class: ConditionalHandler
      Handle a request that has met the conditions. Typically, the implementation will provide optional handling and then call the ConditionalHandler.nextHandler(Request, Response, Callback) method to continue handling.
      Specified by:
      onConditionsMet in class ConditionalHandler
      Parameters:
      request - The request to handle
      response - The response to generate
      callback - The callback for completion
      Returns:
      True if this handler will complete the callback
      Throws:
      Exception - If there is a problem handling
      See Also:
    • onConditionsNotMet

      protected boolean onConditionsNotMet(Request request, Response response, org.eclipse.jetty.util.Callback callback) throws Exception
      Description copied from class: ConditionalHandler
      This method is called when the request has not met the conditions and is not to be handled by this handler. Implementations may return false; send an error response; or handle the request differently.
      Specified by:
      onConditionsNotMet in class ConditionalHandler
      Parameters:
      request - The request to handle
      response - The response to generate
      callback - The callback for completion
      Returns:
      True if this handler will complete the callback
      Throws:
      Exception - If there is a problem handling
      See Also: