Class HttpChannelState.ChannelRequest
- All Implemented Interfaces:
Content.Source
,Request
,Attributes
,Dumpable
- Enclosing class:
- HttpChannelState
-
Nested Class Summary
Nested classes/interfaces inherited from interface org.eclipse.jetty.util.Attributes
Attributes.Layer, Attributes.Lazy, Attributes.Mapped, Attributes.Synthetic, Attributes.Wrapper
Nested classes/interfaces inherited from interface org.eclipse.jetty.util.component.Dumpable
Dumpable.DumpableContainer
Nested classes/interfaces inherited from interface org.eclipse.jetty.server.Request
Request.AttributesWrapper, Request.AuthenticationState, Request.Handler, Request.ServeAs, Request.Wrapper
-
Field Summary
Fields inherited from interface org.eclipse.jetty.util.Attributes
NULL
Fields inherited from interface org.eclipse.jetty.server.Request
COOKIE_ATTRIBUTE, DEFAULT_LOCALES, LOG
-
Method Summary
Modifier and TypeMethodDescriptionvoid
addFailureListener
(Consumer<Throwable> onFailure) Adds a listener for asynchronous fatal failures.void
addHttpStreamWrapper
(Function<HttpStream, HttpStream> wrapper) Add aHttpStream.Wrapper
to the currentHttpStream
.void
addIdleTimeoutListener
(Predicate<TimeoutException> onIdleTimeout) Adds a listener for idle timeouts.boolean
Consume any available content.void
Demands to invoke the given demand callback parameter when a chunk of content is available.boolean
void
Fails this content source with alast
failure chunk
, failing and discarding accumulated content chunks that were not yet read.long
Get the nanoTime at which the request arrived to a connector, obtained viaSystem.nanoTime()
.long
Get theContext
associated with thisRequest
.long
Get the nanoTime at which the request headers were parsed, obtained viaSystem.nanoTime()
.getId()
an ID unique within the lifetime scope of theConnectionMetaData.getId()
).long
getSession
(boolean create) Get aSession
associated with the request.int
hashCode()
boolean
isSecure()
void
push
(MetaData.Request resource) Pushes the givenresource
to the client.read()
Reads a chunk of content.void
setLoggedRequest
(Request request) toString()
Methods inherited from class org.eclipse.jetty.util.Attributes.Lazy
addAll, asAttributeMap, clearAttributes, dump, dump, getAttribute, getAttributeNameSet, removeAttribute, setAttribute, size
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
Methods inherited from interface org.eclipse.jetty.util.Attributes
asAttributeMap, clearAttributes, getAttribute, getAttributeNameSet, removeAttribute, setAttribute
Methods inherited from interface org.eclipse.jetty.io.Content.Source
fail, rewind
-
Method Details
-
setLoggedRequest
-
getLoggedRequest
-
getContentBytesRead
public long getContentBytesRead() -
getId
Description copied from interface:Request
an ID unique within the lifetime scope of theConnectionMetaData.getId()
). This may be a protocol ID (e.g. HTTP/2 stream ID) or it may be unrelated to the protocol. -
getComponents
- Specified by:
getComponents
in interfaceRequest
- Returns:
- the
Components
to be used with thisRequest
.
-
getConnectionMetaData
- Specified by:
getConnectionMetaData
in interfaceRequest
- Returns:
- the
ConnectionMetaData
associated to thisRequest
-
getMethod
-
getHttpURI
- Specified by:
getHttpURI
in interfaceRequest
- Returns:
- the HTTP URI of this
Request
- See Also:
-
getContext
Description copied from interface:Request
Get theContext
associated with thisRequest
.Note that a
Request
should always have an associatedContext
since if theRequest
is not being handled by aContextHandler
then theContext
fromServer.getContext()
will be used.- Specified by:
getContext
in interfaceRequest
- Returns:
- the
Context
associated with thisRequest
. Nevernull
. - See Also:
-
getHeaders
- Specified by:
getHeaders
in interfaceRequest
- Returns:
- the HTTP headers of this
Request
-
getTrailers
- Specified by:
getTrailers
in interfaceRequest
- Returns:
- the HTTP trailers of this
Request
, ornull
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 interfaceRequest
- 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 interfaceRequest
- Returns:
- The nanoTime at which the request was ready in nanoseconds
-
isSecure
public boolean isSecure() -
getLength
public long getLength()- Specified by:
getLength
in interfaceContent.Source
- Returns:
- the content length, if known, or -1 if the content length is unknown
-
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 nullContent.Chunk.getFailure()
, to signal that there was a failure trying to produce a chunk of content, or that the content production has beenfailed
externally - a
Content.Chunk
instance, containing the chunk of content.
Once a read returns an
Content.Chunk
instance with non-nullContent.Chunk.getFailure()
then if the failure islast
further reads will continue to return the same failure chunk instance, otherwise furtherread()
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 returnedContent.Chunk
.Additionally, prior to the ultimate call to
Retainable.release()
, the reader code may make additional calls toRetainable.retain()
, that must ultimately be matched by a correspondent number of calls toRetainable.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 aTrailers
instance, in case of request content trailers.- Specified by:
read
in interfaceContent.Source
- Specified by:
read
in interfaceRequest
- 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 inRequest.read()
and reads directly from theHttpStream
. This reads until there is no content currently available, or it reaches EOF. TheHttpConfiguration.setMaxUnconsumedRequestContentReads(int)
configuration can be used to configure how many reads will be attempted by this method.- Specified by:
consumeAvailable
in interfaceRequest
- Returns:
- true if the content was fully consumed.
-
demand
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 passedRunnable
are serialized and a callback fordemand
call is not invoked until any previousdemand
callback has returned. Thus theRunnable
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 returnnull
.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 interfaceContent.Source
- Specified by:
demand
in interfaceRequest
- Parameters:
demandCallback
- the demand callback to invoke when there is a content chunk available.- See Also:
-
fail
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 nullContent.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 interfaceContent.Source
- Parameters:
failure
- the cause of the failure- See Also:
-
push
Description copied from interface:Request
Pushes the given
resource
to the client. -
addIdleTimeoutListener
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 (seeRequest.addFailureListener(Consumer)
); orfalse
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)
orResponse.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 interfaceRequest
- Parameters:
onIdleTimeout
- the idle timeout listener as a predicate function- See Also:
-
addFailureListener
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:
- Pending
Request.demand(Runnable)
have been woken up. - Calls to
Request.read()
will return theThrowable
failure. - Pending and new
Response.write(boolean, ByteBuffer, Callback)
calls will be failed by callingCallback.failed(Throwable)
on the callback passed toResponse.write(boolean, ByteBuffer, Callback)
.
Listeners are processed in the same order they are added.
- Specified by:
addFailureListener
in interfaceRequest
- Parameters:
onFailure
- the failure listener as a consumer function- See Also:
- Pending
-
getTunnelSupport
- Specified by:
getTunnelSupport
in interfaceRequest
-
addHttpStreamWrapper
Description copied from interface:Request
Add aHttpStream.Wrapper
to the currentHttpStream
.- Specified by:
addHttpStreamWrapper
in interfaceRequest
- Parameters:
wrapper
- A function that wraps the passed stream.- See Also:
-
getSession
Description copied from interface:Request
Get a
Session
associated with the request. Sessions may not be supported by a given configuration, in which casenull
will be returned.- Specified by:
getSession
in interfaceRequest
- Parameters:
create
- True if the session should be created for the request.- Returns:
- The session associated with the request or
null
.
-
hashCode
public int hashCode()- Specified by:
hashCode
in interfaceAttributes
- Overrides:
hashCode
in classAttributes.Lazy
-
equals
- Specified by:
equals
in interfaceAttributes
- Overrides:
equals
in classAttributes.Lazy
-
toString
- Overrides:
toString
in classAttributes.Lazy
-