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 classAnHttpInput.Interceptorthat chains two otherHttpInput.Interceptors together.static classstatic classprotected static classprotected static classstatic interfaceAn interceptor for HTTP Request input.static classA 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 longprivate final HttpChannelStateprivate HttpInput.Contentprivate longprivate longprivate longprivate final Deque<HttpInput.Content> private HttpInput.Contentprivate HttpInput.Interceptorprivate javax.servlet.ReadListenerprivate final byte[]private HttpInput.Stateprivate booleanprotected static final HttpInput.Stateprotected static final HttpInput.Stateprotected static final HttpInput.State(package private) static final HttpInput.Contentprotected static final HttpInput.State(package private) static final HttpInput.Contentprivate static final Loggerprotected static final HttpInput.State -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbooleanaddContent(HttpInput.Content content) Adds some content to this input stream.voidaddInterceptor(HttpInput.Interceptor interceptor) Set theHttpInput.Interceptor, using aHttpInput.ChainedInterceptorif anHttpInput.Interceptoris already set.voidCalled by channel when asynchronous IO needs to produce more contentintprotected voidBlocks until some content or some end-of-file event arrives.private voidconsume(HttpInput.Content content) booleanConsume all available content without blocking.booleanearlyEOF()This method should be called to signal that an EOF has been detected before all the expected content arrived.booleaneof()This method should be called to signal that all the expected content arrived.private Throwablefail(HttpInput.Content content, Throwable failure) booleanprotected intget(HttpInput.Content content, byte[] buffer, int offset, int length) Copies the given content into the given byte buffer.private longlonglongprotected HttpChannelStatebooleanprivate HttpInput.Contentintercept(HttpInput.Content content) booleanisAsync()booleanisError()booleanbooleanisReady()protected HttpInput.ContentGet the next content from the inputQ, callingproduceContent()if need be.protected HttpInput.ContentPoll the inputQ for Content or EOF.protected HttpInput.ContentPoll the inputQ for Content.booleanprotected voidCalled when derived implementations should attempt to produce more Content and add it viaaddContent(Content).protected HttpInput.ContentGet the next readable from the inputQ, callingproduceContent()if need be.intread()intread(byte[] b, int off, int len) voidrecycle()voidrun()voidsetInterceptor(HttpInput.Interceptor interceptor) Set the interceptor.voidsetReadListener(javax.servlet.ReadListener readListener) toString()voidunblock()protected voidwake()private booleanwakeup()Methods inherited from class javax.servlet.ServletInputStream
readLineMethods 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.ChainedInterceptorif anHttpInput.Interceptoris already set.- Parameters:
interceptor- the nextHttpInput.Interceptorin a chain
-
available
public int available()- Overrides:
availablein classInputStream
-
wake
protected void wake() -
getBlockingTimeout
private long getBlockingTimeout() -
read
- Specified by:
readin classInputStream- Throws:
IOException
-
read
- Overrides:
readin 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.SentinelContents 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.SentinelContents 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:
isFinishedin classjavax.servlet.ServletInputStream
-
isReady
public boolean isReady()- Specified by:
isReadyin classjavax.servlet.ServletInputStream
-
setReadListener
public void setReadListener(javax.servlet.ReadListener readListener) - Specified by:
setReadListenerin classjavax.servlet.ServletInputStream
-
onIdleTimeout
-
failed
-
wakeup
private boolean wakeup() -
run
public void run() -
toString
-