Class HttpChannel
- All Implemented Interfaces:
- Runnable,- HttpOutput.Interceptor
- Direct Known Subclasses:
- HttpChannelOverFCGI,- HttpChannelOverHttp,- HttpChannelOverHTTP2
- 
Nested Class SummaryNested ClassesModifier and TypeClassDescriptionstatic interfaceListener forHttpChannelevents.static classDeprecated.
- 
Field SummaryFields
- 
Constructor SummaryConstructorsConstructorDescriptionHttpChannel(Connector connector, HttpConfiguration configuration, EndPoint endPoint, HttpTransport transport) 
- 
Method SummaryModifier and TypeMethodDescriptionvoidIf a write or similar operation to this channel fails, then this method should be called.booleanaddListener(HttpChannel.Listener listener) Deprecated.voidaddRequestLog(RequestLog requestLog) protected booleanChecks whether the processing of the request resulted in an upgrade, and if so performs upgrade preparation steps before the upgrade response is sent back to the client.protected voidcommit(MetaData.Response info) voidcontinue100(int available) If the associated response has the Expect header set to 100 Continue, then accessing the input stream indicates that the handler/servlet is ready for the request body and thus a 100 Continue response is sent.voidprotected abstract booleaneof()Mark the channel's input as EOF.protected voidabstract booleanfailAllContent(Throwable failure) Fail all content that is currently stored within the channel.abstract booleanFail the channel's input.protected StringformatAddrOrHost(String addr) Format the address or host returned from Request methodslonglongGet the idle timeout.Return the local name of the connected channel.intReturn the Local Port of the connected channel.longgetState()Deprecated.booleanhandle()protected voidhandleException(Throwable failure) Sends an error 500, performing a special logic to detect whether the request is suspended, to avoid concurrent writes from the application.booleanbooleanbooleanbooleanbooleanbooleanbooleanbooleanbooleanbooleanabstract booleanNotify the channel that content is needed.protected HttpOutputvoidonBadMessage(BadMessageException failure) voidbooleanonContent(HttpInput.Content content) booleanvoidonRequest(MetaData.Request request) booleanvoidonTrailers(HttpFields trailers) abstract HttpInput.ContentProduce aHttpInput.Contentobject with data currently stored within the channel.voidrecycle()booleanremoveListener(HttpChannel.Listener listener) Deprecated.voidReset the buffers.voidrun()booleansendErrorOrAbort(String message) booleansendResponse(MetaData.Response info, ByteBuffer content, boolean complete) protected booleansendResponse(MetaData.Response response, ByteBuffer content, boolean complete, Callback callback) voidvoidsetIdleTimeout(long timeoutMs) Set the idle timeout.voidsetRequestLog(RequestLog requestLog) toString()protected ThrowableUnwrap failure causes to find target classvoidwrite(ByteBuffer content, boolean complete, Callback callback) Non-Blocking write, committing the response if needed.
- 
Field Details- 
NOOP_LISTENER
 
- 
- 
Constructor Details- 
HttpChannelpublic HttpChannel(Connector connector, HttpConfiguration configuration, EndPoint endPoint, HttpTransport transport) 
 
- 
- 
Method Details- 
isSendErrorpublic boolean isSendError()
- 
formatAddrOrHostFormat the address or host returned from Request methods- Parameters:
- addr- The address or host
- Returns:
- Default implementation returns HostPort.normalizeHost(String)
 
- 
needContentpublic abstract boolean needContent()Notify the channel that content is needed. If some content is immediately available, true is returned andproduceContent()has to be called and will return a non-null object. If no content is immediately available, an attempt to produce content must be made; if new content has been produced, true is returned; otherwiseHttpInput.onContentProducible()is called once some content arrives andproduceContent()can be called without returningnull. If a failure happens, thenHttpInput.onContentProducible()will be called and an error content will return the error on the next call toproduceContent().- Returns:
- true if content is immediately available.
 
- 
produceContentProduce aHttpInput.Contentobject with data currently stored within the channel. The produced content can be special (meaning callingHttpInput.Content.isSpecial()returns true) if the channel reached a special state, like EOF or an error. Once a special content has been returned, all subsequent calls to this method will always return a special content of the same kind andneedContent()will always return true. The returned content is "raw", i.e.: not decoded.- Returns:
- a HttpInput.Contentobject if one is immediately available without blocking, null otherwise.
 
- 
failAllContentFail all content that is currently stored within the channel.- Parameters:
- failure- the failure to fail the content with.
- Returns:
- true if EOF was reached while failing all content, false otherwise.
 
- 
failedFail the channel's input.- Parameters:
- failure- the failure.
- Returns:
- true if the channel needs to be rescheduled.
 
- 
eofprotected abstract boolean eof()Mark the channel's input as EOF.- Returns:
- true if the channel needs to be rescheduled.
 
- 
newHttpOutput
- 
getState
- 
addListenerDeprecated.Add a transient Listener to the HttpChannel.Listeners added by this method will only be notified if the HttpChannel has been constructed with an instance of HttpChannel.TransientListenersas anAbstractConnectorprovided listenerTransient listeners are removed after every request cycle - Parameters:
- listener- the listener to add
- Returns:
- true if the listener was added.
 
- 
removeListenerDeprecated.
- 
getTransientListenersDeprecated.
- 
getBytesWrittenpublic long getBytesWritten()
- 
getRequestspublic long getRequests()- Returns:
- the number of requests handled by this connection
 
- 
getConnector
- 
getHttpTransport
- 
getRequestLog
- 
setRequestLog
- 
addRequestLog
- 
getCommittedMetaData
- 
getIdleTimeoutpublic long getIdleTimeout()Get the idle timeout.This is implemented as a call to EndPoint.getIdleTimeout(), but may be overridden by channels that have timeouts different from their connections.- Returns:
- the idle timeout (in milliseconds)
 
- 
setIdleTimeoutpublic void setIdleTimeout(long timeoutMs) Set the idle timeout.This is implemented as a call to EndPoint.setIdleTimeout(long), but may be overridden by channels that have timeouts different from their connections.- Parameters:
- timeoutMs- the idle timeout in milliseconds
 
- 
getByteBufferPool
- 
getHttpConfiguration
- 
getServer
- 
getRequest
- 
getResponse
- 
getConnection
- 
getEndPoint
- 
getLocalNameReturn the local name of the connected channel. This is the host name after the connector is bound and the connection is accepted. Value can be overridden by HttpConfiguration.setLocalAddress(SocketAddress).Note: some connectors are not based on IP networking, and default behavior here will result in a null return. Use HttpConfiguration.setLocalAddress(SocketAddress)to set the value to an acceptable host name.- Returns:
- the local name, or null
 
- 
getLocalPortpublic int getLocalPort()Return the Local Port of the connected channel. This is the port the connector is bound to and is accepting connections on. Value can be overridden by HttpConfiguration.setLocalAddress(SocketAddress).Note: some connectors are not based on IP networking, and default behavior here will result in a value of 0 returned. Use HttpConfiguration.setLocalAddress(SocketAddress)to set the value to an acceptable port.- Returns:
- the local port, or 0 if unspecified
 
- 
getLocalAddress
- 
getRemoteAddress
- 
getServerAuthority- Returns:
- return the HttpConfiguration server authority override
 
- 
continue100If the associated response has the Expect header set to 100 Continue, then accessing the input stream indicates that the handler/servlet is ready for the request body and thus a 100 Continue response is sent.- Parameters:
- available- estimate of the number of bytes that are available
- Throws:
- IOException- if the InputStream cannot be created
 
- 
recyclepublic void recycle()
- 
runpublic void run()
- 
handlepublic boolean handle()- Returns:
- True if the channel is ready to continue handling (ie it is not suspended)
 
- 
ensureConsumeAllOrNotPersistentpublic void ensureConsumeAllOrNotPersistent()
- 
sendErrorOrAbort- Parameters:
- message- the error message.
- Returns:
- true if we have sent an error, false if we have aborted.
 
- 
handleExceptionSends an error 500, performing a special logic to detect whether the request is suspended, to avoid concurrent writes from the application. It may happen that the application suspends, and then throws an exception, while an application spawned thread writes the response content; in such case, we attempt to commit the error directly bypassing the ErrorHandlermechanisms and the response OutputStream.- Parameters:
- failure- the Throwable that caused the problem
 
- 
unwrapUnwrap failure causes to find target class- Parameters:
- failure- The throwable to have its causes unwrapped
- targets- Exception classes that we should not unwrap
- Returns:
- A target throwable or null
 
- 
sendResponseAndCompletepublic void sendResponseAndComplete()
- 
isExpecting100Continuepublic boolean isExpecting100Continue()
- 
isExpecting102Processingpublic boolean isExpecting102Processing()
- 
toString
- 
onRequest
- 
onContent
- 
onContentCompletepublic boolean onContentComplete()
- 
onTrailers
- 
onRequestCompletepublic boolean onRequestComplete()
- 
checkAndPrepareUpgradeprotected boolean checkAndPrepareUpgrade()Checks whether the processing of the request resulted in an upgrade, and if so performs upgrade preparation steps before the upgrade response is sent back to the client. This avoids a race where the server is unprepared if the client sends data immediately after having received the upgrade response. - Returns:
- true if the channel is not complete and more processing is required, typically because sendError has been called.
 
- 
onCompletedpublic void onCompleted()
- 
onBadMessage
- 
sendResponseprotected boolean sendResponse(MetaData.Response response, ByteBuffer content, boolean complete, Callback callback) 
- 
sendResponsepublic boolean sendResponse(MetaData.Response info, ByteBuffer content, boolean complete) throws IOException - Throws:
- IOException
 
- 
commit
- 
isCommittedpublic boolean isCommitted()
- 
isRequestCompletedpublic boolean isRequestCompleted()- Returns:
- True if the request lifecycle is completed
 
- 
isResponseCompletedpublic boolean isResponseCompleted()- Returns:
- True if the response is completely written.
 
- 
isPersistentpublic boolean isPersistent()
- 
writeNon-Blocking write, committing the response if needed. Called as last link in HttpOutput.Filter chain- Specified by:
- writein interface- HttpOutput.Interceptor
- Parameters:
- content- the content buffer to write
- complete- whether the content is complete for the response
- callback- Callback when complete or failed
 
- 
resetBufferpublic void resetBuffer()Description copied from interface:HttpOutput.InterceptorReset the buffers.If the Interceptor contains buffers then reset them. - Specified by:
- resetBufferin interface- HttpOutput.Interceptor
 
- 
getNextInterceptor- Specified by:
- getNextInterceptorin interface- HttpOutput.Interceptor
- Returns:
- The next Interceptor in the chain or null if this is the last Interceptor in the chain.
 
- 
execute
- 
getScheduler
- 
isUseInputDirectByteBufferspublic boolean isUseInputDirectByteBuffers()
- 
isUseOutputDirectByteBufferspublic boolean isUseOutputDirectByteBuffers()
- 
abortIf a write or similar operation to this channel fails, then this method should be called.The standard implementation calls HttpTransport.abort(Throwable).- Parameters:
- failure- the failure that caused the abort.
 
- 
isTunnellingSupportedpublic boolean isTunnellingSupported()
- 
getTunnellingEndPoint
 
-