Interface Request

All Superinterfaces:
org.eclipse.jetty.util.Attributes, org.eclipse.jetty.io.Content.Source
All Known Subinterfaces:
Request.ServeAs
All Known Implementing Classes:
ContextRequest, ErrorHandler.ErrorRequest, GzipRequest, HeaderWrappingRequest, Request.AttributesWrapper, Request.Wrapper, SecureRequestCustomizer.SecureRequest, SecureRequestCustomizer.SecureRequestWithSslSessionData, StatisticsHandler.MinimumDataRateHandler.MinimumDataRateRequest

public interface Request extends org.eclipse.jetty.util.Attributes, org.eclipse.jetty.io.Content.Source

The representation of an HTTP request, for any protocol version (HTTP/1.1, HTTP/2, HTTP/3).

The typical idiom to read request content is the following:


 public boolean handle(Request request, Response response, Callback callback)
 {
     // Reject requests not appropriate for this handler.
     if (!request.getHttpURI().getPath().startsWith("/yourPath"))
         return false;

     while (true)
     {
         Content.Chunk chunk = request.read();
         if (chunk == null)
         {
             // The chunk is not currently available, demand to be called back.
             request.demand(() -> handle(request, response, callback));
             return true;
         }

         if (Content.Chunk.isError(chunk))
         {
             Throwable failure = error.getCause();

             // Handle errors.
             // If the chunk is not last, then the error can be ignored and reading can be tried again.
             // Otherwise, if the chunk is last, or we do not wish to ignore a non-last error, then
             // mark the handling as complete, either generating a custom
             // response and succeeding the callback, or failing the callback.
             callback.failed(failure);
             return true;
         }

         if (chunk instanceof Trailers trailers)
         {
             HttpFields fields = trailers.getTrailers();

             // Handle trailers.

             // Generate a response.

             // Mark the handling as complete.
             callback.succeeded();

             return true;
         }

         // Normal chunk, process it.
         processChunk(chunk);
         // Release the content after processing.
         chunk.release();

         // Reached end-of-file?
         if (chunk.isLast())
         {
             // Generate a response.

             // Mark the handling as complete.
             callback.succeeded();

             return true;
         }
     }
 }