Class Request.Wrapper

java.lang.Object
org.eclipse.jetty.server.Request.Wrapper
All Implemented Interfaces:
Content.Source, Request, Attributes
Direct Known Subclasses:
ContextRequest, GzipRequest, HeaderWrappingRequest, Request.AttributesWrapper, Rule.Handler, SecureRequestCustomizer.SecureRequest, ServerUpgradeRequestDelegate, ServerUpgradeRequestImpl, StatisticsHandler.MinimumDataRateHandler.MinimumDataRateRequest
Enclosing interface:
Request

public static class Request.Wrapper extends Object implements Request, Attributes

A wrapper for Request instances.

  • Constructor Details

    • Wrapper

      public Wrapper(Request wrapped)
  • Method Details

    • getId

      public String getId()
      Description copied from interface: Request
      an ID unique within the lifetime scope of the ConnectionMetaData.getId()). This may be a protocol ID (e.g. HTTP/2 stream ID) or it may be unrelated to the protocol.
      Specified by:
      getId in interface Request
      See Also:
    • getComponents

      public Components getComponents()
      Specified by:
      getComponents in interface Request
      Returns:
      the Components to be used with this Request.
    • getConnectionMetaData

      public ConnectionMetaData getConnectionMetaData()
      Specified by:
      getConnectionMetaData in interface Request
      Returns:
      the ConnectionMetaData associated to this Request
    • getMethod

      public String getMethod()
      Specified by:
      getMethod in interface Request
      Returns:
      the HTTP method of this Request
    • getHttpURI

      public HttpURI getHttpURI()
      Specified by:
      getHttpURI in interface Request
      Returns:
      the HTTP URI of this Request
      See Also:
    • getContext

      public Context getContext()
      Description copied from interface: Request
      Get the Context associated with this Request.

      Note that a Request should always have an associated Context since if the Request is not being handled by a ContextHandler then the Context from Server.getContext() will be used.

      Specified by:
      getContext in interface Request
      Returns:
      the Context associated with this Request. Never null.
      See Also:
    • getHeaders

      public HttpFields getHeaders()
      Specified by:
      getHeaders in interface Request
      Returns:
      the HTTP headers of this Request
    • getTrailers

      public HttpFields getTrailers()
      Specified by:
      getTrailers in interface Request
      Returns:
      the HTTP trailers of this Request, or null if they are not present
    • getBeginNanoTime

      public long getBeginNanoTime()
      Description copied from interface: Request

      Get the nanoTime at which the request arrived to a connector, obtained via System.nanoTime(). This method can be used when measuring latencies.

      Specified by:
      getBeginNanoTime in interface Request
      Returns:
      The nanoTime at which the request was received/created in nanoseconds
    • getHeadersNanoTime

      public long getHeadersNanoTime()
      Description copied from interface: Request

      Get the nanoTime at which the request headers were parsed, obtained via System.nanoTime(). This method can be used when measuring latencies.

      Specified by:
      getHeadersNanoTime in interface Request
      Returns:
      The nanoTime at which the request was ready in nanoseconds
    • isSecure

      public boolean isSecure()
      Specified by:
      isSecure in interface Request
    • getLength

      public long getLength()
      Specified by:
      getLength in interface Content.Source
      Returns:
      the content length, if known, or -1 if the content length is unknown
    • read

      public Content.Chunk read()
      Description copied from interface: Request

      Reads a chunk of content.

      See how to use this method idiomatically.

      The returned chunk could be:

      • null, to signal that there isn't a chunk of content available
      • an Content.Chunk instance with non null Content.Chunk.getFailure(), to signal that there was a failure trying to produce a chunk of content, or that the content production has been failed externally
      • a Content.Chunk instance, containing the chunk of content.

      Once a read returns an Content.Chunk instance with non-null Content.Chunk.getFailure() then if the failure is last further reads will continue to return the same failure chunk instance, otherwise further read() operations may return different non-failure chunks.

      Once a read returns a last chunk, further reads will continue to return a last chunk (although the instance may be different).

      The content reader code must ultimately arrange for a call to Retainable.release() on the returned Content.Chunk.

      Additionally, prior to the ultimate call to Retainable.release(), the reader code may make additional calls to Retainable.retain(), that must ultimately be matched by a correspondent number of calls to Retainable.release().

      Concurrent reads from different threads are not recommended, as they are inherently in a race condition.

      Reads performed outside the invocation context of a demand callback are allowed. However, reads performed with a pending demand are inherently in a race condition (the thread that reads with the thread that invokes the demand callback).

      In addition, the returned Content.Chunk may be a Trailers instance, in case of request content trailers.

      Specified by:
      read in interface Content.Source
      Specified by:
      read in interface Request
      Returns:
      a chunk of content, possibly a failure instance, or null
      See Also:
    • consumeAvailable

      public boolean consumeAvailable()
      Description copied from interface: Request
      Consume any available content. This bypasses any request wrappers to process the content in Request.read() and reads directly from the HttpStream. This reads until there is no content currently available, or it reaches EOF. The HttpConfiguration.setMaxUnconsumedRequestContentReads(int) configuration can be used to configure how many reads will be attempted by this method.
      Specified by:
      consumeAvailable in interface Request
      Returns:
      true if the content was fully consumed.
    • demand

      public void demand(Runnable demandCallback)
      Description copied from interface: Request

      Demands to invoke the given demand callback parameter when a chunk of content is available.

      See how to use this method idiomatically.

      Implementations guarantee that calls to this method are safely reentrant so that stack overflows are avoided in the case of mutual recursion between the execution of the Runnable callback and a call to this method. Invocations of the passed Runnable are serialized and a callback for demand call is not invoked until any previous demand callback has returned. Thus the Runnable should not block waiting for a callback of a future demand call.

      The demand callback may be invoked spuriously: a subsequent call to Content.Source.read() may return null.

      Calling this method establishes a pending demand, which is fulfilled when the demand callback is invoked.

      Calling this method when there is already a pending demand results in an IllegalStateException to be thrown.

      If the invocation of the demand callback throws an exception, then Content.Source.fail(Throwable) is called.

      Specified by:
      demand in interface Content.Source
      Specified by:
      demand in interface Request
      Parameters:
      demandCallback - the demand callback to invoke when there is a content chunk available.
      See Also:
    • fail

      public void fail(Throwable failure)
      Description copied from interface: Content.Source

      Fails this content source with a last failure chunk, failing and discarding accumulated content chunks that were not yet read.

      The failure may be notified to the content reader at a later time, when the content reader reads a content chunk, via a Content.Chunk instance with a non null Content.Chunk.getFailure().

      If Content.Source.read() has returned a last chunk, this is a no operation.

      Typical failure: the content being aborted by user code, or idle timeouts.

      If this method has already been called, then it is a no operation.

      Specified by:
      fail in interface Content.Source
      Parameters:
      failure - the cause of the failure
      See Also:
    • push

      public void push(MetaData.Request resource)
      Description copied from interface: Request

      Pushes the given resource to the client.

      Specified by:
      push in interface Request
      Parameters:
      resource - the resource to push
      See Also:
    • addIdleTimeoutListener

      public void addIdleTimeoutListener(Predicate<TimeoutException> onIdleTimeout)
      Description copied from interface: Request

      Adds a listener for idle timeouts.

      The listener is a predicate function that should return true to indicate that the idle timeout should be handled by the container as a fatal failure (see Request.addFailureListener(Consumer)); or false to ignore that specific timeout and for another timeout to occur after another idle period.

      Idle timeout listeners are only invoked if there are no pending Request.demand(Runnable) or Response.write(boolean, ByteBuffer, Callback) operations.

      Listeners are processed in the same order they are added, and the first that returns true stops the processing of subsequent listeners, which are therefore not invoked.

      Specified by:
      addIdleTimeoutListener in interface Request
      Parameters:
      onIdleTimeout - the idle timeout listener as a predicate function
      See Also:
    • addFailureListener

      public void addFailureListener(Consumer<Throwable> onFailure)
      Description copied from interface: Request

      Adds a listener for asynchronous fatal failures.

      When a listener is called, the effects of the failure have already taken place:

      Listeners are processed in the same order they are added.

      Specified by:
      addFailureListener in interface Request
      Parameters:
      onFailure - the failure listener as a consumer function
      See Also:
    • getTunnelSupport

      public TunnelSupport getTunnelSupport()
      Specified by:
      getTunnelSupport in interface Request
    • addHttpStreamWrapper

      public void addHttpStreamWrapper(Function<HttpStream,HttpStream> wrapper)
      Description copied from interface: Request
      Add a HttpStream.Wrapper to the current HttpStream.
      Specified by:
      addHttpStreamWrapper in interface Request
      Parameters:
      wrapper - A function that wraps the passed stream.
      See Also:
    • getSession

      public Session getSession(boolean create)
      Description copied from interface: Request

      Get a Session associated with the request. Sessions may not be supported by a given configuration, in which case null will be returned.

      Specified by:
      getSession in interface Request
      Parameters:
      create - True if the session should be created for the request.
      Returns:
      The session associated with the request or null.
    • removeAttribute

      public Object removeAttribute(String name)
      Description copied from interface: Attributes
      Remove an attribute
      Specified by:
      removeAttribute in interface Attributes
      Parameters:
      name - the attribute to remove
      Returns:
      the value of the attribute if removed, else null
    • setAttribute

      public Object setAttribute(String name, Object attribute)
      Description copied from interface: Attributes
      Set an attribute
      Specified by:
      setAttribute in interface Attributes
      Parameters:
      name - the attribute to set
      attribute - the value to set. A null value is equivalent to removing the attribute.
      Returns:
      the previous value of the attribute if set, else null
    • getAttribute

      public Object getAttribute(String name)
      Description copied from interface: Attributes
      Get an attribute
      Specified by:
      getAttribute in interface Attributes
      Parameters:
      name - the attribute to get
      Returns:
      the value of the attribute
    • getAttributeNameSet

      public Set<String> getAttributeNameSet()
      Description copied from interface: Attributes
      Get the immutable set of attribute names.
      Specified by:
      getAttributeNameSet in interface Attributes
      Returns:
      Set of attribute names
    • asAttributeMap

      public Map<String,Object> asAttributeMap()
      Specified by:
      asAttributeMap in interface Attributes
    • clearAttributes

      public void clearAttributes()
      Description copied from interface: Attributes
      Clear all attribute names
      Specified by:
      clearAttributes in interface Attributes
    • getWrapped

      public Request getWrapped()