public abstract class Http2BaseFilter extends HttpBaseFilter
Filter
serves as a bridge
between HTTP2 frames and upper-level HTTP layers by converting Http2Frame
s into
HttpPacket
s and passing them up/down by the FilterChain
.
Additionally this Filter
has
logic responsible for checking HTTP2 protocol semantics and fire correspondent
events and messages in case when HTTP2 semantics is broken.Modifier and Type | Field and Description |
---|---|
protected static TransferEncoding |
FIXED_LENGTH_ENCODING |
Constructor and Description |
---|
Http2BaseFilter()
Constructs Http2HandlerFilter.
|
Http2BaseFilter(DraftVersion... supportedDraftVersions)
Constructs Http2HandlerFilter.
|
Http2BaseFilter(ExecutorService threadPool,
DraftVersion... supportedDraftVersions)
Constructs Http2HandlerFilter.
|
Modifier and Type | Method and Description |
---|---|
protected boolean |
checkRequestHeadersOnUpgrade(HttpRequestPacket httpRequest) |
protected boolean |
checkResponseHeadersOnUpgrade(HttpResponsePacket httpResponse) |
protected Http2Connection |
createHttp2Connection(DraftVersion draftVersion,
Connection connection,
boolean isServer)
Creates
Http2Connection with preconfigured initial-windows-size and
max-concurrent-streams |
protected SettingsFrame |
getHttp2UpgradeSettings(HttpRequestPacket httpRequest) |
protected DraftVersion |
getHttp2UpgradingVersion(HttpHeader httpHeader) |
int |
getInitialWindowSize() |
int |
getLocalMaxFramePayloadSize() |
int |
getMaxConcurrentStreams() |
NextAction |
handleEvent(FilterChainContext ctx,
FilterChainEvent event)
Handle custom event associated with the
Connection . |
NextAction |
handleWrite(FilterChainContext ctx)
Execute a unit of processing work to be performed, when some data should
be written on channel.
|
protected Http2Connection |
obtainHttp2Connection(FilterChainContext context,
boolean isUpStream)
Obtain
Http2Connection associated with the Connection
and prepare it for use. |
protected void |
onHttpContentEncoded(HttpContent content,
FilterChainContext ctx)
Invoked when a HTTP body chunk has been encoded in preparation to being
transmitted to the user-agent.
|
protected void |
onHttpContentError(HttpHeader httpHeader,
FilterChainContext ctx,
Throwable t)
Callback which is invoked when parsing an HTTP message payload fails.
|
protected void |
onHttpContentParsed(HttpContent content,
FilterChainContext ctx)
Invoked as request/response body content has been processed by this
Filter . |
protected void |
onHttpHeaderError(HttpHeader httpHeader,
FilterChainContext ctx,
Throwable t)
Callback which is invoked when parsing an HTTP message header fails.
|
protected boolean |
onHttpHeaderParsed(HttpHeader httpHeader,
Buffer buffer,
FilterChainContext ctx)
Callback invoked when the HTTP message header parsing is complete.
|
protected void |
onHttpHeadersEncoded(HttpHeader httpHeader,
FilterChainContext ctx)
Invoked when HTTP headers have been encoded in preparation to being
transmitted to the user-agent.
|
protected void |
onHttpHeadersParsed(HttpHeader httpHeader,
FilterChainContext ctx)
Invoked when all headers of the packet have been parsed.
|
protected boolean |
onHttpPacketParsed(HttpHeader httpHeader,
FilterChainContext ctx)
Callback method, called when
HttpPacket parsing has been completed. |
protected void |
onInitialLineEncoded(HttpHeader httpHeader,
FilterChainContext ctx)
Invoked when the intial response line has been encoded in preparation
to being transmitted to the user-agent.
|
protected void |
onInitialLineParsed(HttpHeader httpHeader,
FilterChainContext ctx)
Invoked when either the request line or status line has been parsed.
|
protected void |
onPrefaceReceived(Http2Connection http2Connection) |
protected void |
prepareOutgoingRequest(HttpRequestPacket request) |
protected abstract void |
processCompleteHeader(Http2Connection http2Connection,
FilterChainContext context,
HeaderBlockHead firstHeaderFrame)
The method is called once complete HTTP header block arrives on
Http2Connection . |
protected boolean |
processFrames(FilterChainContext ctx,
Http2Connection http2Connection,
List<Http2Frame> framesList) |
protected abstract void |
processOutgoingHttpHeader(FilterChainContext ctx,
Http2Connection http2Connection,
HttpHeader httpHeader,
HttpPacket entireHttpPacket) |
protected void |
sendSettings(Http2Connection http2Connection,
FilterChainContext context) |
void |
setInitialWindowSize(int initialWindowSize)
Sets the default initial stream window size (in bytes) for new HTTP2 connections.
|
void |
setLocalMaxFramePayloadSize(int localMaxFramePayloadSize)
Sets the maximum allowed HTTP2 frame size.
|
void |
setMaxConcurrentStreams(int maxConcurrentStreams)
Sets the default maximum number of concurrent streams allowed for one session.
|
bind
createContext, exceptionOccurred, handleAccept, handleClose, handleConnect, handleRead, onAdded, onFilterChainChanged, onRemoved, toString
protected static final TransferEncoding FIXED_LENGTH_ENCODING
public Http2BaseFilter()
public Http2BaseFilter(DraftVersion... supportedDraftVersions)
supportedDraftVersions
- HTTP2 draft versions this filter has to supportpublic Http2BaseFilter(ExecutorService threadPool, DraftVersion... supportedDraftVersions)
threadPool
- the ExecutorService
to be used to process SynStreamFrame
and
SynReplyFrame
frames, if null mentioned frames will be processed in the same thread they were parsed.supportedDraftVersions
- HTTP2 draft versions this filter has to supportpublic int getLocalMaxFramePayloadSize()
public void setLocalMaxFramePayloadSize(int localMaxFramePayloadSize)
localMaxFramePayloadSize
- the maximum allowed HTTP2 frame sizepublic void setMaxConcurrentStreams(int maxConcurrentStreams)
maxConcurrentStreams
- public int getMaxConcurrentStreams()
public void setInitialWindowSize(int initialWindowSize)
initialWindowSize
- public int getInitialWindowSize()
protected boolean processFrames(FilterChainContext ctx, Http2Connection http2Connection, List<Http2Frame> framesList)
protected boolean checkRequestHeadersOnUpgrade(HttpRequestPacket httpRequest)
protected boolean checkResponseHeadersOnUpgrade(HttpResponsePacket httpResponse)
protected SettingsFrame getHttp2UpgradeSettings(HttpRequestPacket httpRequest)
protected DraftVersion getHttp2UpgradingVersion(HttpHeader httpHeader)
protected boolean onHttpPacketParsed(HttpHeader httpHeader, FilterChainContext ctx)
HttpPacket
parsing has been completed.httpHeader
- HttpHeader
, which represents parsed HTTP packet headerctx
- processing context.true
if an error has occurred while processing
the header portion of the HTTP request, otherwise returns
false
.protected boolean onHttpHeaderParsed(HttpHeader httpHeader, Buffer buffer, FilterChainContext ctx)
httpHeader
- HttpHeader
, which represents parsed HTTP packet headerbuffer
- Buffer
the header was parsed fromctx
- processing context.true
if an error has occurred while processing
the header portion of the HTTP request, otherwise returns
false
.protected void onInitialLineParsed(HttpHeader httpHeader, FilterChainContext ctx)
Invoked when either the request line or status line has been parsed.
httpHeader
- HttpHeader
, which represents HTTP packet headerctx
- processing context.protected void onInitialLineEncoded(HttpHeader httpHeader, FilterChainContext ctx)
Invoked when the intial response line has been encoded in preparation to being transmitted to the user-agent.
httpHeader
- HttpHeader
, which represents HTTP packet headerctx
- processing context.protected void onHttpHeadersParsed(HttpHeader httpHeader, FilterChainContext ctx)
Invoked when all headers of the packet have been parsed. Depending on the transfer encoding being used by the current request, this method may be invoked multiple times.
httpHeader
- HttpHeader
, which represents HTTP packet headerctx
- processing context.protected void onHttpHeadersEncoded(HttpHeader httpHeader, FilterChainContext ctx)
Invoked when HTTP headers have been encoded in preparation to being transmitted to the user-agent.
httpHeader
- HttpHeader
, which represents HTTP packet headerctx
- processing context.protected void onHttpContentParsed(HttpContent content, FilterChainContext ctx)
Invoked as request/response body content has been processed by this
Filter
.
content
- request/response body contentctx
- processing context.protected void onHttpContentEncoded(HttpContent content, FilterChainContext ctx)
Invoked when a HTTP body chunk has been encoded in preparation to being transmitted to the user-agent.
content
- HttpContent
, which represents HTTP packet headerctx
- processing context.protected void onHttpHeaderError(HttpHeader httpHeader, FilterChainContext ctx, Throwable t) throws IOException
Callback which is invoked when parsing an HTTP message header fails. The processing logic has to take care about error handling and following connection closing.
httpHeader
- HttpHeader
, which represents HTTP packet headerctx
- the FilterChainContext
processing this requestt
- the cause of the errorIOException
protected void onHttpContentError(HttpHeader httpHeader, FilterChainContext ctx, Throwable t) throws IOException
Callback which is invoked when parsing an HTTP message payload fails. The processing logic has to take care about error handling and following connection closing.
httpHeader
- HttpHeader
, which represents HTTP packet headerctx
- the FilterChainContext
processing this requestt
- the cause of the errorIOException
protected abstract void processCompleteHeader(Http2Connection http2Connection, FilterChainContext context, HeaderBlockHead firstHeaderFrame) throws IOException
Http2Connection
.http2Connection
- context
- firstHeaderFrame
- IOException
public NextAction handleWrite(FilterChainContext ctx) throws IOException
BaseFilter
Filter
may either complete the required processing and
return false, or delegate remaining processing to the next
Filter
in a FilterChain
containing this Filter
by returning true.handleWrite
in interface Filter
handleWrite
in class BaseFilter
ctx
- FilterChainContext
NextAction
instruction for FilterChain
, how it
should continue the executionIOException
protected abstract void processOutgoingHttpHeader(FilterChainContext ctx, Http2Connection http2Connection, HttpHeader httpHeader, HttpPacket entireHttpPacket) throws IOException
IOException
protected void prepareOutgoingRequest(HttpRequestPacket request)
public NextAction handleEvent(FilterChainContext ctx, FilterChainEvent event) throws IOException
BaseFilter
Connection
.
This Filter
may either complete the required processing and
return StopAction
, or delegate remaining processing to the next
Filter
in a FilterChain
containing this Filter
by returning InvokeAction
.handleEvent
in interface Filter
handleEvent
in class BaseFilter
ctx
- FilterChainContext
NextAction
instruction for FilterChain
, how it
should continue the executionIOException
protected Http2Connection createHttp2Connection(DraftVersion draftVersion, Connection connection, boolean isServer)
Http2Connection
with preconfigured initial-windows-size and
max-concurrent-streamsdraftVersion
- connection
- isServer
- Http2Connection
protected void onPrefaceReceived(Http2Connection http2Connection)
protected final Http2Connection obtainHttp2Connection(FilterChainContext context, boolean isUpStream)
Http2Connection
associated with the Connection
and prepare it for use.context
- FilterChainContext
isUpStream
- true if the FilterChainContext
represents
upstream FilterChain
execution, or false otherwiseHttp2Connection
associated with the Connection
and prepare it for useprotected void sendSettings(Http2Connection http2Connection, FilterChainContext context)
Copyright © 2021 Oracle Corporation. All rights reserved.