Package org.eclipse.jetty.server
Class HttpInput
java.lang.Object
java.io.InputStream
javax.servlet.ServletInputStream
org.eclipse.jetty.server.HttpInput
- All Implemented Interfaces:
Closeable
,AutoCloseable
,Runnable
- Direct Known Subclasses:
HttpInputOverHTTP
HttpInput
provides an implementation of ServletInputStream
for HttpChannel
.
Content may arrive in patterns such as [content(), content(), messageComplete()] so that this class maintains two states: the content state that tells whether there is content to consume and the EOF state that tells whether an EOF has arrived. Only once the content has been consumed the content state is moved to the EOF state.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic class
AnHttpInput.Interceptor
that chains two otherHttpInput.Interceptor
s together.static class
static class
protected static class
protected static class
static interface
An interceptor for HTTP Request input.static class
A Sentinel Content, which has zero length content but indicates some other event in the input stream (eg EOF)protected static class
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate long
private final HttpChannelState
private HttpInput.Content
private long
private long
private long
private final Deque
<HttpInput.Content> private HttpInput.Content
private HttpInput.Interceptor
private javax.servlet.ReadListener
private final byte[]
private HttpInput.State
private boolean
protected static final HttpInput.State
protected static final HttpInput.State
protected static final HttpInput.State
(package private) static final HttpInput.Content
protected static final HttpInput.State
(package private) static final HttpInput.Content
private static final Logger
protected static final HttpInput.State
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionboolean
addContent
(HttpInput.Content content) Adds some content to this input stream.void
addInterceptor
(HttpInput.Interceptor interceptor) Set theHttpInput.Interceptor
, using aHttpInput.ChainedInterceptor
if anHttpInput.Interceptor
is already set.void
Called by channel when asynchronous IO needs to produce more contentint
protected void
Blocks until some content or some end-of-file event arrives.private void
consume
(HttpInput.Content content) boolean
Consume all available content without blocking.boolean
earlyEOF()
This method should be called to signal that an EOF has been detected before all the expected content arrived.boolean
eof()
This method should be called to signal that all the expected content arrived.private Throwable
fail
(HttpInput.Content content, Throwable failure) boolean
protected int
get
(HttpInput.Content content, byte[] buffer, int offset, int length) Copies the given content into the given byte buffer.private long
long
long
protected HttpChannelState
boolean
private HttpInput.Content
intercept
(HttpInput.Content content) boolean
isAsync()
boolean
isError()
boolean
boolean
isReady()
protected HttpInput.Content
Get the next content from the inputQ, callingproduceContent()
if need be.protected HttpInput.Content
Poll the inputQ for Content or EOF.protected HttpInput.Content
Poll the inputQ for Content.boolean
protected void
Called when derived implementations should attempt to produce more Content and add it viaaddContent(Content)
.protected HttpInput.Content
Get the next readable from the inputQ, callingproduceContent()
if need be.int
read()
int
read
(byte[] b, int off, int len) void
recycle()
void
run()
void
setInterceptor
(HttpInput.Interceptor interceptor) Set the interceptor.void
setReadListener
(javax.servlet.ReadListener readListener) toString()
void
unblock()
protected void
wake()
private boolean
wakeup()
Methods inherited from class javax.servlet.ServletInputStream
readLine
Methods inherited from class java.io.InputStream
close, mark, markSupported, nullInputStream, read, readAllBytes, readNBytes, readNBytes, reset, skip, skipNBytes, transferTo
-
Field Details
-
LOG
-
EOF_CONTENT
-
EARLY_EOF_CONTENT
-
_oneByteBuffer
private final byte[] _oneByteBuffer -
_content
-
_intercepted
-
_inputQ
-
_channelState
-
_listener
private javax.servlet.ReadListener _listener -
_state
-
_firstByteTimeStamp
private long _firstByteTimeStamp -
_contentArrived
private long _contentArrived -
_contentConsumed
private long _contentConsumed -
_blockUntil
private long _blockUntil -
_waitingForContent
private boolean _waitingForContent -
_interceptor
-
STREAM
-
ASYNC
-
EARLY_EOF
-
EOF
-
AEOF
-
-
Constructor Details
-
HttpInput
-
-
Method Details
-
getHttpChannelState
-
recycle
public void recycle() -
fail
-
getInterceptor
- Returns:
- The current Interceptor, or null if none set
-
setInterceptor
Set the interceptor.- Parameters:
interceptor
- The interceptor to use.
-
addInterceptor
Set theHttpInput.Interceptor
, using aHttpInput.ChainedInterceptor
if anHttpInput.Interceptor
is already set.- Parameters:
interceptor
- the nextHttpInput.Interceptor
in a chain
-
available
public int available()- Overrides:
available
in classInputStream
-
wake
protected void wake() -
getBlockingTimeout
private long getBlockingTimeout() -
read
- Specified by:
read
in classInputStream
- Throws:
IOException
-
read
- Overrides:
read
in classInputStream
- Throws:
IOException
-
produceContent
Called when derived implementations should attempt to produce more Content and add it viaaddContent(Content)
. For protocols that are constantly producing (eg HTTP2) this can be left as a noop;- Throws:
IOException
- if unable to produce content
-
asyncReadProduce
Called by channel when asynchronous IO needs to produce more content- Throws:
IOException
- if unable to produce content
-
nextContent
Get the next content from the inputQ, callingproduceContent()
if need be. EOF is processed and state changed.- Returns:
- the content or null if none available.
- Throws:
IOException
- if retrieving the content fails
-
nextNonSentinelContent
Poll the inputQ for Content. Consumed buffers andHttpInput.SentinelContent
s are removed and EOF state updated if need be.- Returns:
- Content or null
- Throws:
IOException
-
produceNextContent
Get the next readable from the inputQ, callingproduceContent()
if need be. EOF is NOT processed and state is not changed.- Returns:
- the content or EOF or null if none available.
- Throws:
IOException
- if retrieving the content fails
-
nextInterceptedContent
Poll the inputQ for Content or EOF. Consumed buffers and non EOFHttpInput.SentinelContent
s are removed. EOF state is not updated. Interception is done within this method.- Returns:
- Content with remaining, a
HttpInput.SentinelContent
, or null - Throws:
IOException
-
intercept
- Throws:
IOException
-
consume
-
get
Copies the given content into the given byte buffer.- Parameters:
content
- the content to copy frombuffer
- the buffer to copy intooffset
- the buffer offset to start copying fromlength
- the space available in the buffer- Returns:
- the number of bytes actually copied
-
blockForContent
Blocks until some content or some end-of-file event arrives.- Throws:
IOException
- if the wait is interrupted
-
addContent
Adds some content to this input stream.- Parameters:
content
- the content to add- Returns:
- true if content channel woken for read
-
hasContent
public boolean hasContent() -
unblock
public void unblock() -
getContentConsumed
public long getContentConsumed() -
getContentReceived
public long getContentReceived() -
earlyEOF
public boolean earlyEOF()This method should be called to signal that an EOF has been detected before all the expected content arrived.Typically this will result in an EOFException being thrown from a subsequent read rather than a -1 return.
- Returns:
- true if content channel woken for read
-
eof
public boolean eof()This method should be called to signal that all the expected content arrived.- Returns:
- true if content channel woken for read
-
consumeAll
public boolean consumeAll()Consume all available content without blocking. Raw content is counted in thegetContentReceived()
statistics, but is not intercepted nor counted in thegetContentConsumed()
statistics- Returns:
- True if EOF was reached, false otherwise.
-
isError
public boolean isError() -
isAsync
public boolean isAsync() -
isFinished
public boolean isFinished()- Specified by:
isFinished
in classjavax.servlet.ServletInputStream
-
isReady
public boolean isReady()- Specified by:
isReady
in classjavax.servlet.ServletInputStream
-
setReadListener
public void setReadListener(javax.servlet.ReadListener readListener) - Specified by:
setReadListener
in classjavax.servlet.ServletInputStream
-
onIdleTimeout
-
failed
-
wakeup
private boolean wakeup() -
run
public void run() -
toString
-