public abstract class HttpCodecFilter extends HttpBaseFilter implements org.glassfish.grizzly.monitoring.MonitoringAware<HttpProbe>
Filter, responsible for transforming Buffer into
HttpPacket and vice versa in asynchronous mode.
When the HttpCodecFilter is added to a FilterChain, on read phase
it consumes incoming Buffer and provides HttpContent as
the result of transformation. On write phase the HttpCodecFilter consumes
input HttpPacket and serializes it to a Buffer, which
gets passed farther as the result of transformation.
So transformations, provided by this filter are following:
(read phase): Buffer -> HttpContent
(write phase): HttpPacket -> Buffer.HttpServerFilter,
HttpClientFilter| Modifier and Type | Class and Description |
|---|---|
static class |
HttpCodecFilter.ContentParsingState |
static class |
HttpCodecFilter.HeaderParsingState |
| Modifier and Type | Field and Description |
|---|---|
protected boolean |
chunkingEnabled |
protected static byte[] |
CLOSE_BYTES
Close bytes.
|
protected org.glassfish.grizzly.utils.ArraySet<ContentEncoding> |
contentEncodings |
static int |
DEFAULT_MAX_HTTP_PACKET_HEADER_SIZE |
protected static byte[] |
KEEPALIVE_BYTES
Keep-alive bytes.
|
protected int |
maxHeadersSize |
protected long |
maxPayloadRemainderToSkip
The maximum request payload remainder (in bytes) HttpServerFilter will try
to swallow after HTTP request processing is over in order to keep the
connection alive.
|
protected org.glassfish.grizzly.monitoring.DefaultMonitoringConfig<HttpProbe> |
monitoringConfig
File cache probes
|
protected boolean |
preserveHeaderCase |
| Constructor and Description |
|---|
HttpCodecFilter(boolean chunkingEnabled,
int maxHeadersSize)
Constructor, which creates HttpCodecFilter instance, with the specific
max header size parameter.
|
| Modifier and Type | Method and Description |
|---|---|
void |
addContentEncoding(ContentEncoding contentEncoding)
Adds the specified
ContentEncoding to the HttpCodecFilter. |
void |
addTransferEncoding(TransferEncoding transferEncoding)
Adds the specified
TransferEncoding to the HttpCodecFilter. |
protected Object |
createJmxManagementObject() |
protected boolean |
decodeHttpPacket(org.glassfish.grizzly.filterchain.FilterChainContext ctx,
HttpPacketParsing httpPacket,
org.glassfish.grizzly.Buffer input) |
protected boolean |
decodeHttpPacketFromBuffer(org.glassfish.grizzly.filterchain.FilterChainContext ctx,
HttpPacketParsing httpPacket,
org.glassfish.grizzly.Buffer input) |
protected boolean |
decodeHttpPacketFromBytes(org.glassfish.grizzly.filterchain.FilterChainContext ctx,
HttpPacketParsing httpPacket,
org.glassfish.grizzly.Buffer inputBuffer) |
protected org.glassfish.grizzly.Buffer |
encodeHttpPacket(org.glassfish.grizzly.filterchain.FilterChainContext ctx,
HttpHeader httpHeader,
HttpContent httpContent,
boolean isContentAlreadyEncoded) |
protected org.glassfish.grizzly.Buffer |
encodeHttpPacket(org.glassfish.grizzly.filterchain.FilterChainContext ctx,
HttpPacket input) |
protected static org.glassfish.grizzly.Buffer |
encodeKnownHeaders(org.glassfish.grizzly.memory.MemoryManager memoryManager,
org.glassfish.grizzly.Buffer buffer,
HttpHeader httpHeader) |
protected static org.glassfish.grizzly.Buffer |
encodeMimeHeader(org.glassfish.grizzly.memory.MemoryManager memoryManager,
org.glassfish.grizzly.Buffer buffer,
DataChunk name,
DataChunk value,
byte[] tempBuffer,
boolean encodeLastCRLF) |
protected static org.glassfish.grizzly.Buffer |
encodeMimeHeaders(org.glassfish.grizzly.memory.MemoryManager memoryManager,
org.glassfish.grizzly.Buffer buffer,
MimeHeaders mimeHeaders,
byte[] tempEncodingBuffer) |
ContentEncoding[] |
getContentEncodings()
Gets registered
ContentEncodings. |
long |
getMaxPayloadRemainderToSkip() |
org.glassfish.grizzly.monitoring.MonitoringConfig<HttpProbe> |
getMonitoringConfig() |
TransferEncoding[] |
getTransferEncodings()
Gets registered
TransferEncodings. |
org.glassfish.grizzly.filterchain.NextAction |
handleRead(org.glassfish.grizzly.filterchain.FilterChainContext ctx,
HttpHeader httpHeader)
The method is called by the specific HttpCodecFilter implementation,
once we have received a
Buffer, which has to be transformed
into HTTP packet part. |
org.glassfish.grizzly.filterchain.NextAction |
handleWrite(org.glassfish.grizzly.filterchain.FilterChainContext ctx)
The method is called, once we need to serialize a
HttpPacket,
which may represent HTTP packet header, content or content chunk. |
protected boolean |
isChunkingEnabled()
Return
true if chunked transfer-encoding may be used. |
boolean |
isPreserveHeaderCase() |
boolean |
isRemoveHandledContentEncodingHeaders() |
protected static boolean |
isSecure(org.glassfish.grizzly.Connection connection)
flag, which indicates whether this HttpCodecFilter is dealing with
the secured HTTP packets.
|
protected abstract void |
onHttpContentEncoded(HttpContent content,
org.glassfish.grizzly.filterchain.FilterChainContext ctx)
Invoked when a HTTP body chunk has been encoded in preparation to being
transmitted to the user-agent.
|
protected abstract void |
onHttpContentError(HttpHeader httpHeader,
org.glassfish.grizzly.filterchain.FilterChainContext ctx,
Throwable t)
Callback which is invoked when parsing an HTTP message payload fails.
|
protected abstract void |
onHttpContentParsed(HttpContent content,
org.glassfish.grizzly.filterchain.FilterChainContext ctx)
Invoked as request/response body content has been processed by this
Filter. |
protected abstract void |
onHttpHeaderError(HttpHeader httpHeader,
org.glassfish.grizzly.filterchain.FilterChainContext ctx,
Throwable t)
Callback which is invoked when parsing an HTTP message header fails.
|
protected abstract boolean |
onHttpHeaderParsed(HttpHeader httpHeader,
org.glassfish.grizzly.Buffer buffer,
org.glassfish.grizzly.filterchain.FilterChainContext ctx)
Callback invoked when the HTTP message header parsing is complete.
|
protected abstract void |
onHttpHeadersEncoded(HttpHeader httpHeader,
org.glassfish.grizzly.filterchain.FilterChainContext ctx)
Invoked when HTTP headers have been encoded in preparation to being
transmitted to the user-agent.
|
protected abstract void |
onHttpHeadersParsed(HttpHeader httpHeader,
MimeHeaders headers,
org.glassfish.grizzly.filterchain.FilterChainContext ctx)
Invoked when HTTP headers portion comes for
HttpHeader message. |
protected abstract boolean |
onHttpPacketParsed(HttpHeader httpHeader,
org.glassfish.grizzly.filterchain.FilterChainContext ctx)
Callback method, called when
HttpPacket parsing has been completed. |
protected void |
onIncomingUpgrade(org.glassfish.grizzly.filterchain.FilterChainContext ctx,
HttpHeader httpHeader)
The method is called, when a peer sends an upgrade HTTP packet
(either request or response).
|
protected abstract void |
onInitialLineEncoded(HttpHeader httpHeader,
org.glassfish.grizzly.filterchain.FilterChainContext ctx)
Invoked when the initial response line has been encoded in preparation
to being transmitted to the user-agent.
|
protected abstract void |
onInitialLineParsed(HttpHeader httpHeader,
org.glassfish.grizzly.filterchain.FilterChainContext ctx)
Invoked when either the request line or status line has been parsed.
|
protected void |
onOutgoingUpgrade(org.glassfish.grizzly.filterchain.FilterChainContext ctx,
HttpHeader httpHeader) |
protected boolean |
parseHeaderFromBuffer(HttpHeader httpHeader,
MimeHeaders mimeHeaders,
HttpCodecFilter.HeaderParsingState parsingState,
org.glassfish.grizzly.Buffer input) |
protected boolean |
parseHeaderFromBytes(HttpHeader httpHeader,
MimeHeaders mimeHeaders,
HttpCodecFilter.HeaderParsingState parsingState,
byte[] input,
int end) |
protected boolean |
parseHeaderName(HttpHeader httpHeader,
MimeHeaders mimeHeaders,
HttpCodecFilter.HeaderParsingState parsingState,
org.glassfish.grizzly.Buffer input) |
protected boolean |
parseHeaderName(HttpHeader httpHeader,
MimeHeaders mimeHeaders,
HttpCodecFilter.HeaderParsingState parsingState,
byte[] input,
int end) |
protected boolean |
parseHeadersFromBuffer(HttpHeader httpHeader,
MimeHeaders mimeHeaders,
HttpCodecFilter.HeaderParsingState parsingState,
org.glassfish.grizzly.Buffer input) |
protected boolean |
parseHeadersFromBytes(HttpHeader httpHeader,
MimeHeaders mimeHeaders,
HttpCodecFilter.HeaderParsingState parsingState,
byte[] input,
int end) |
protected static int |
parseHeaderValue(HttpHeader httpHeader,
HttpCodecFilter.HeaderParsingState parsingState,
org.glassfish.grizzly.Buffer input) |
protected static int |
parseHeaderValue(HttpHeader httpHeader,
HttpCodecFilter.HeaderParsingState parsingState,
byte[] input,
int end) |
boolean |
removeContentEncoding(ContentEncoding contentEncoding)
Removes the specified
ContentEncoding from the HttpCodecFilter. |
boolean |
removeTransferEncoding(TransferEncoding transferEncoding)
Removes the specified
TransferEncoding from the HttpCodecFilter. |
void |
setMaxPayloadRemainderToSkip(long maxPayloadRemainderToSkip)
Set the maximum request payload remainder (in bytes) HttpServerFilter
will try to swallow after HTTP request processing is over in order to
keep the connection alive.
|
void |
setPreserveHeaderCase(boolean preserveHeaderCase)
Set to
true to preserve header case. |
void |
setRemoveHandledContentEncodingHeaders(boolean removeHandledContentEncodingHeaders)
If enabled the content-encoding header for handled content-encodings
is removed.
|
protected static boolean |
statusDropsConnection(int status)
Determine if we must drop the connection because of the HTTP status
code.
|
bindpublic static final int DEFAULT_MAX_HTTP_PACKET_HEADER_SIZE
protected static final byte[] CLOSE_BYTES
protected static final byte[] KEEPALIVE_BYTES
protected final org.glassfish.grizzly.utils.ArraySet<ContentEncoding> contentEncodings
protected final boolean chunkingEnabled
protected long maxPayloadRemainderToSkip
protected final org.glassfish.grizzly.monitoring.DefaultMonitoringConfig<HttpProbe> monitoringConfig
protected final int maxHeadersSize
protected boolean preserveHeaderCase
public HttpCodecFilter(boolean chunkingEnabled,
int maxHeadersSize)
chunkingEnabled - true if the chunked transfer encoding
should be used when no explicit content length has been set.maxHeadersSize - the maximum size of the HTTP message header.protected abstract boolean onHttpPacketParsed(HttpHeader httpHeader, org.glassfish.grizzly.filterchain.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.sprotected abstract boolean onHttpHeaderParsed(HttpHeader httpHeader, org.glassfish.grizzly.Buffer buffer, org.glassfish.grizzly.filterchain.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 abstract void onInitialLineParsed(HttpHeader httpHeader, org.glassfish.grizzly.filterchain.FilterChainContext ctx)
Invoked when either the request line or status line has been parsed.
httpHeader - HttpHeader, which represents HTTP packet headerctx - processing context.protected abstract void onInitialLineEncoded(HttpHeader httpHeader, org.glassfish.grizzly.filterchain.FilterChainContext ctx)
Invoked when the initial response line has been encoded in preparation to being transmitted to the user-agent.
httpHeader - HttpHeader, which represents HTTP packet headerctx - processing context.protected abstract void onHttpHeadersParsed(HttpHeader httpHeader, MimeHeaders headers, org.glassfish.grizzly.filterchain.FilterChainContext ctx)
Invoked when HTTP headers portion comes for HttpHeader message.
Depending on the transfer encoding being used by the current request, this method may be
invoked multiple times.
httpHeader - HttpHeader, which represents HTTP packet headerheaders - the headers portion, that has been parsedctx - processing context.protected abstract void onHttpHeadersEncoded(HttpHeader httpHeader, org.glassfish.grizzly.filterchain.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 abstract void onHttpContentParsed(HttpContent content, org.glassfish.grizzly.filterchain.FilterChainContext ctx)
Invoked as request/response body content has been processed by this
Filter.
content - request/response body contentctx - processing context.protected abstract void onHttpContentEncoded(HttpContent content, org.glassfish.grizzly.filterchain.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 abstract void onHttpHeaderError(HttpHeader httpHeader, org.glassfish.grizzly.filterchain.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 errorIOExceptionprotected abstract void onHttpContentError(HttpHeader httpHeader, org.glassfish.grizzly.filterchain.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 errorIOExceptionpublic long getMaxPayloadRemainderToSkip()
public void setMaxPayloadRemainderToSkip(long maxPayloadRemainderToSkip)
maxPayloadRemainderToSkip - public boolean isPreserveHeaderCase()
true if header case will be preserved, otherwise false.
Default is false.public void setPreserveHeaderCase(boolean preserveHeaderCase)
true to preserve header case. Default is false.preserveHeaderCase - true to preserve header case.public TransferEncoding[] getTransferEncodings()
Gets registered TransferEncodings.
TransferEncodings.public void addTransferEncoding(TransferEncoding transferEncoding)
Adds the specified TransferEncoding to the HttpCodecFilter.
transferEncoding - the TransferEncoding to addpublic boolean removeTransferEncoding(TransferEncoding transferEncoding)
Removes the specified TransferEncoding from the HttpCodecFilter.
transferEncoding - the TransferEncoding to removetrue if the TransferEncoding was removed, otherwise
false indicating the TransferEncoding was not already
presentpublic ContentEncoding[] getContentEncodings()
Gets registered ContentEncodings.
ContentEncodings.public void addContentEncoding(ContentEncoding contentEncoding)
Adds the specified ContentEncoding to the HttpCodecFilter.
contentEncoding - the ContentEncoding to addpublic boolean removeContentEncoding(ContentEncoding contentEncoding)
Removes the specified ContentEncoding from the HttpCodecFilter.
contentEncoding - the ContentEncoding to removetrue if the ContentEncoding was removed, otherwise
false indicating the ContentEncoding was not already
presentprotected boolean isChunkingEnabled()
true if chunked transfer-encoding may be used.true if chunked transfer-encoding may be used.public boolean isRemoveHandledContentEncodingHeaders()
true if content-encoding headers that are handled
by this module should be removed from the headersetRemoveHandledContentEncodingHeaders(boolean)public void setRemoveHandledContentEncodingHeaders(boolean removeHandledContentEncodingHeaders)
If enabled the content-encoding header for handled content-encodings is removed.
The primary usecase for this option is the use in a servlet container
that enables compression handling on the server level. In this case
the next level (the webapplication) has to be notified, that compression
of the stream has been dealt with.
For this usecase it is assumed, that a servlet filter might be present
that also does compression/decompression. To prevent double decompression
the content-encoding header is removed, so the servlet filter can't
assume it needs to decode.
removeHandledContentEncodingHeaders - true if
content-encoding headers that are handled by this module should be
removed from the headerpublic final org.glassfish.grizzly.filterchain.NextAction handleRead(org.glassfish.grizzly.filterchain.FilterChainContext ctx,
HttpHeader httpHeader)
throws IOException
Buffer, which has to be transformed
into HTTP packet part.
Filter gets Buffer, which represents a part or complete HTTP
message. As the result of "read" transformation - we will get
HttpContent message, which will represent HTTP packet content
(might be zero length content) and reference to a HttpHeader,
which contains HTTP message header.ctx - Request processing contexthttpHeader - the current HttpHeader, which is being processed.NextActionIOExceptionprotected boolean decodeHttpPacket(org.glassfish.grizzly.filterchain.FilterChainContext ctx,
HttpPacketParsing httpPacket,
org.glassfish.grizzly.Buffer input)
protected boolean decodeHttpPacketFromBytes(org.glassfish.grizzly.filterchain.FilterChainContext ctx,
HttpPacketParsing httpPacket,
org.glassfish.grizzly.Buffer inputBuffer)
protected boolean parseHeadersFromBytes(HttpHeader httpHeader, MimeHeaders mimeHeaders, HttpCodecFilter.HeaderParsingState parsingState, byte[] input, int end)
protected boolean parseHeaderFromBytes(HttpHeader httpHeader, MimeHeaders mimeHeaders, HttpCodecFilter.HeaderParsingState parsingState, byte[] input, int end)
protected boolean parseHeaderName(HttpHeader httpHeader, MimeHeaders mimeHeaders, HttpCodecFilter.HeaderParsingState parsingState, byte[] input, int end)
protected static int parseHeaderValue(HttpHeader httpHeader, HttpCodecFilter.HeaderParsingState parsingState, byte[] input, int end)
protected boolean decodeHttpPacketFromBuffer(org.glassfish.grizzly.filterchain.FilterChainContext ctx,
HttpPacketParsing httpPacket,
org.glassfish.grizzly.Buffer input)
protected boolean parseHeadersFromBuffer(HttpHeader httpHeader, MimeHeaders mimeHeaders, HttpCodecFilter.HeaderParsingState parsingState, org.glassfish.grizzly.Buffer input)
protected boolean parseHeaderFromBuffer(HttpHeader httpHeader, MimeHeaders mimeHeaders, HttpCodecFilter.HeaderParsingState parsingState, org.glassfish.grizzly.Buffer input)
protected boolean parseHeaderName(HttpHeader httpHeader, MimeHeaders mimeHeaders, HttpCodecFilter.HeaderParsingState parsingState, org.glassfish.grizzly.Buffer input)
protected static int parseHeaderValue(HttpHeader httpHeader, HttpCodecFilter.HeaderParsingState parsingState, org.glassfish.grizzly.Buffer input)
public org.glassfish.grizzly.filterchain.NextAction handleWrite(org.glassfish.grizzly.filterchain.FilterChainContext ctx)
throws IOException
HttpPacket,
which may represent HTTP packet header, content or content chunk.
Filter gets HttpPacket, which represents a HTTP header, content,
or content part. As the result of "write" transformation - we will get
Buffer, which will represent serialized HTTP packet.handleWrite in interface org.glassfish.grizzly.filterchain.FilterhandleWrite in class org.glassfish.grizzly.filterchain.BaseFilterctx - Request processing contextNextActionIOExceptionprotected void onIncomingUpgrade(org.glassfish.grizzly.filterchain.FilterChainContext ctx,
HttpHeader httpHeader)
ctx - httpHeader - protected void onOutgoingUpgrade(org.glassfish.grizzly.filterchain.FilterChainContext ctx,
HttpHeader httpHeader)
protected org.glassfish.grizzly.Buffer encodeHttpPacket(org.glassfish.grizzly.filterchain.FilterChainContext ctx,
HttpPacket input)
protected final org.glassfish.grizzly.Buffer encodeHttpPacket(org.glassfish.grizzly.filterchain.FilterChainContext ctx,
HttpHeader httpHeader,
HttpContent httpContent,
boolean isContentAlreadyEncoded)
protected static org.glassfish.grizzly.Buffer encodeKnownHeaders(org.glassfish.grizzly.memory.MemoryManager memoryManager,
org.glassfish.grizzly.Buffer buffer,
HttpHeader httpHeader)
protected static org.glassfish.grizzly.Buffer encodeMimeHeaders(org.glassfish.grizzly.memory.MemoryManager memoryManager,
org.glassfish.grizzly.Buffer buffer,
MimeHeaders mimeHeaders,
byte[] tempEncodingBuffer)
protected static org.glassfish.grizzly.Buffer encodeMimeHeader(org.glassfish.grizzly.memory.MemoryManager memoryManager,
org.glassfish.grizzly.Buffer buffer,
DataChunk name,
DataChunk value,
byte[] tempBuffer,
boolean encodeLastCRLF)
protected static boolean isSecure(org.glassfish.grizzly.Connection connection)
HttpRequestPacket or
HttpResponsePacket.connection - ConnectionConnection is secured, or false
otherwiseprotected static boolean statusDropsConnection(int status)
public org.glassfish.grizzly.monitoring.MonitoringConfig<HttpProbe> getMonitoringConfig()
getMonitoringConfig in interface org.glassfish.grizzly.monitoring.MonitoringAware<HttpProbe>protected Object createJmxManagementObject()
Copyright © 2020 Oracle Corporation. All Rights Reserved.