- All Implemented Interfaces:
org.glassfish.grizzly.filterchain.Filter,org.glassfish.grizzly.monitoring.MonitoringAware<HttpProbe>
- Direct Known Subclasses:
HttpClientFilter,HttpServerFilter
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.- Author:
- Alexey Stashok
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final classstatic final class -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final booleanprotected static final byte[]Close bytes.protected final org.glassfish.grizzly.utils.ArraySet<ContentEncoding>static final intprotected static final byte[]Keep-alive bytes.protected final intprotected longThe 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 final org.glassfish.grizzly.monitoring.DefaultMonitoringConfig<HttpProbe>File cache probesprotected boolean -
Constructor Summary
ConstructorsConstructorDescriptionHttpCodecFilter(boolean chunkingEnabled, int maxHeadersSize) Constructor, which creates HttpCodecFilter instance, with the specific max header size parameter. -
Method Summary
Modifier and TypeMethodDescriptionvoidaddContentEncoding(ContentEncoding contentEncoding) Adds the specifiedContentEncodingto theHttpCodecFilter.voidaddTransferEncoding(TransferEncoding transferEncoding) Adds the specifiedTransferEncodingto theHttpCodecFilter.protected Objectprotected booleandecodeHttpPacket(org.glassfish.grizzly.filterchain.FilterChainContext ctx, HttpPacketParsing httpPacket, org.glassfish.grizzly.Buffer input) protected booleandecodeHttpPacketFromBuffer(org.glassfish.grizzly.filterchain.FilterChainContext ctx, HttpPacketParsing httpPacket, org.glassfish.grizzly.Buffer input) protected booleandecodeHttpPacketFromBytes(org.glassfish.grizzly.filterchain.FilterChainContext ctx, HttpPacketParsing httpPacket, org.glassfish.grizzly.Buffer inputBuffer) protected final org.glassfish.grizzly.BufferencodeHttpPacket(org.glassfish.grizzly.filterchain.FilterChainContext ctx, HttpHeader httpHeader, HttpContent httpContent, boolean isContentAlreadyEncoded) protected org.glassfish.grizzly.BufferencodeHttpPacket(org.glassfish.grizzly.filterchain.FilterChainContext ctx, HttpPacket input) protected static org.glassfish.grizzly.BufferencodeKnownHeaders(org.glassfish.grizzly.memory.MemoryManager memoryManager, org.glassfish.grizzly.Buffer buffer, HttpHeader httpHeader) protected static org.glassfish.grizzly.BufferencodeMimeHeader(org.glassfish.grizzly.memory.MemoryManager memoryManager, org.glassfish.grizzly.Buffer buffer, DataChunk name, DataChunk value, byte[] tempBuffer, boolean encodeLastCRLF) protected static org.glassfish.grizzly.BufferencodeMimeHeaders(org.glassfish.grizzly.memory.MemoryManager memoryManager, org.glassfish.grizzly.Buffer buffer, MimeHeaders mimeHeaders, byte[] tempEncodingBuffer) Gets registeredContentEncodings.longorg.glassfish.grizzly.monitoring.MonitoringConfig<HttpProbe>Gets registeredTransferEncodings.final org.glassfish.grizzly.filterchain.NextActionhandleRead(org.glassfish.grizzly.filterchain.FilterChainContext ctx, HttpHeader httpHeader) The method is called by the specific HttpCodecFilter implementation, once we have received aBuffer, which has to be transformed into HTTP packet part.org.glassfish.grizzly.filterchain.NextActionhandleWrite(org.glassfish.grizzly.filterchain.FilterChainContext ctx) The method is called, once we need to serialize aHttpPacket, which may represent HTTP packet header, content or content chunk.protected booleanReturntrueif chunked transfer-encoding may be used.booleanbooleanprotected static booleanisSecure(org.glassfish.grizzly.Connection connection) flag, which indicates whether this HttpCodecFilter is dealing with the secured HTTP packets.protected abstract voidonHttpContentEncoded(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 voidonHttpContentError(HttpHeader httpHeader, org.glassfish.grizzly.filterchain.FilterChainContext ctx, Throwable t) Callback which is invoked when parsing an HTTP message payload fails.protected abstract voidonHttpContentParsed(HttpContent content, org.glassfish.grizzly.filterchain.FilterChainContext ctx) Invoked as request/response body content has been processed by thisFilter.protected abstract voidonHttpHeaderError(HttpHeader httpHeader, org.glassfish.grizzly.filterchain.FilterChainContext ctx, Throwable t) Callback which is invoked when parsing an HTTP message header fails.protected abstract booleanonHttpHeaderParsed(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 voidonHttpHeadersEncoded(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 voidonHttpHeadersParsed(HttpHeader httpHeader, MimeHeaders headers, org.glassfish.grizzly.filterchain.FilterChainContext ctx) Invoked when HTTP headers portion comes forHttpHeadermessage.protected abstract booleanonHttpPacketParsed(HttpHeader httpHeader, org.glassfish.grizzly.filterchain.FilterChainContext ctx) Callback method, called whenHttpPacketparsing has been completed.protected voidonIncomingUpgrade(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 voidonInitialLineEncoded(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 voidonInitialLineParsed(HttpHeader httpHeader, org.glassfish.grizzly.filterchain.FilterChainContext ctx) Invoked when either the request line or status line has been parsed.protected voidonOutgoingUpgrade(org.glassfish.grizzly.filterchain.FilterChainContext ctx, HttpHeader httpHeader) protected booleanparseHeaderFromBuffer(HttpHeader httpHeader, MimeHeaders mimeHeaders, HttpCodecFilter.HeaderParsingState parsingState, org.glassfish.grizzly.Buffer input) protected booleanparseHeaderFromBytes(HttpHeader httpHeader, MimeHeaders mimeHeaders, HttpCodecFilter.HeaderParsingState parsingState, byte[] input, int end) protected booleanparseHeaderName(HttpHeader httpHeader, MimeHeaders mimeHeaders, HttpCodecFilter.HeaderParsingState parsingState, byte[] input, int end) protected booleanparseHeaderName(HttpHeader httpHeader, MimeHeaders mimeHeaders, HttpCodecFilter.HeaderParsingState parsingState, org.glassfish.grizzly.Buffer input) protected booleanparseHeadersFromBuffer(HttpHeader httpHeader, MimeHeaders mimeHeaders, HttpCodecFilter.HeaderParsingState parsingState, org.glassfish.grizzly.Buffer input) protected booleanparseHeadersFromBytes(HttpHeader httpHeader, MimeHeaders mimeHeaders, HttpCodecFilter.HeaderParsingState parsingState, byte[] input, int end) protected static intparseHeaderValue(HttpHeader httpHeader, HttpCodecFilter.HeaderParsingState parsingState, byte[] input, int end) protected static intparseHeaderValue(HttpHeader httpHeader, HttpCodecFilter.HeaderParsingState parsingState, org.glassfish.grizzly.Buffer input) booleanremoveContentEncoding(ContentEncoding contentEncoding) Removes the specifiedContentEncodingfrom theHttpCodecFilter.booleanremoveTransferEncoding(TransferEncoding transferEncoding) Removes the specifiedTransferEncodingfrom theHttpCodecFilter.voidsetMaxPayloadRemainderToSkip(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.voidsetPreserveHeaderCase(boolean preserveHeaderCase) Set totrueto preserve header case.voidsetRemoveHandledContentEncodingHeaders(boolean removeHandledContentEncodingHeaders) If enabled the content-encoding header for handled content-encodings is removed.protected static booleanstatusDropsConnection(int status) Determine if we must drop the connection because of the HTTP status code.Methods inherited from class org.glassfish.grizzly.http.HttpBaseFilter
bindMethods inherited from class org.glassfish.grizzly.filterchain.BaseFilter
createContext, exceptionOccurred, handleAccept, handleClose, handleConnect, handleEvent, handleRead, onAdded, onFilterChainChanged, onRemoved, toString
-
Field Details
-
DEFAULT_MAX_HTTP_PACKET_HEADER_SIZE
public static final int DEFAULT_MAX_HTTP_PACKET_HEADER_SIZE- See Also:
-
CLOSE_BYTES
protected static final byte[] CLOSE_BYTESClose bytes. -
KEEPALIVE_BYTES
protected static final byte[] KEEPALIVE_BYTESKeep-alive bytes. -
contentEncodings
-
chunkingEnabled
protected final boolean chunkingEnabled -
maxPayloadRemainderToSkip
protected long maxPayloadRemainderToSkipThe maximum request payload remainder (in bytes) HttpServerFilter will try to swallow after HTTP request processing is over in order to keep the connection alive. If the remainder is too large - HttpServerFilter will close the connection. -
monitoringConfig
protected final org.glassfish.grizzly.monitoring.DefaultMonitoringConfig<HttpProbe> monitoringConfigFile cache probes -
maxHeadersSize
protected final int maxHeadersSize -
preserveHeaderCase
protected boolean preserveHeaderCase
-
-
Constructor Details
-
HttpCodecFilter
public HttpCodecFilter(boolean chunkingEnabled, int maxHeadersSize) Constructor, which creates HttpCodecFilter instance, with the specific max header size parameter.- Parameters:
chunkingEnabled-trueif the chunked transfer encoding should be used when no explicit content length has been set.maxHeadersSize- the maximum size of the HTTP message header.
-
-
Method Details
-
onHttpPacketParsed
protected abstract boolean onHttpPacketParsed(HttpHeader httpHeader, org.glassfish.grizzly.filterchain.FilterChainContext ctx) Callback method, called whenHttpPacketparsing has been completed.- Parameters:
httpHeader-HttpHeader, which represents parsed HTTP packet headerctx- processing context.- Returns:
trueif an error has occurred while processing the header portion of the HTTP request, otherwise returnsfalse.s
-
onHttpHeaderParsed
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.- Parameters:
httpHeader-HttpHeader, which represents parsed HTTP packet headerbuffer-Bufferthe header was parsed fromctx- processing context.- Returns:
trueif an error has occurred while processing the header portion of the HTTP request, otherwise returnsfalse.
-
onInitialLineParsed
protected abstract void onInitialLineParsed(HttpHeader httpHeader, org.glassfish.grizzly.filterchain.FilterChainContext ctx) Invoked when either the request line or status line has been parsed.
- Parameters:
httpHeader-HttpHeader, which represents HTTP packet headerctx- processing context.
-
onInitialLineEncoded
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.
- Parameters:
httpHeader-HttpHeader, which represents HTTP packet headerctx- processing context.- Since:
- 2.1.2
-
onHttpHeadersParsed
protected abstract void onHttpHeadersParsed(HttpHeader httpHeader, MimeHeaders headers, org.glassfish.grizzly.filterchain.FilterChainContext ctx) Invoked when HTTP headers portion comes for
HttpHeadermessage. Depending on the transfer encoding being used by the current request, this method may be invoked multiple times.- Parameters:
httpHeader-HttpHeader, which represents HTTP packet headerheaders- the headers portion, that has been parsedctx- processing context.
-
onHttpHeadersEncoded
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.
- Parameters:
httpHeader-HttpHeader, which represents HTTP packet headerctx- processing context.- Since:
- 2.1.2
-
onHttpContentParsed
protected abstract void onHttpContentParsed(HttpContent content, org.glassfish.grizzly.filterchain.FilterChainContext ctx) Invoked as request/response body content has been processed by this
Filter.- Parameters:
content- request/response body contentctx- processing context.
-
onHttpContentEncoded
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.
- Parameters:
content-HttpContent, which represents HTTP packet headerctx- processing context.- Since:
- 2.1.2
-
onHttpHeaderError
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.
- Parameters:
httpHeader-HttpHeader, which represents HTTP packet headerctx- theFilterChainContextprocessing this requestt- the cause of the error- Throws:
IOException
-
onHttpContentError
protected 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.
- Parameters:
httpHeader-HttpHeader, which represents HTTP packet headerctx- theFilterChainContextprocessing this requestt- the cause of the error- Throws:
IOException
-
getMaxPayloadRemainderToSkip
public long getMaxPayloadRemainderToSkip()- Returns:
- 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. If the remainder is too large - the connection will be closed. -1 means no limits will be applied.
- Since:
- 2.3.13
-
setMaxPayloadRemainderToSkip
public 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. If the remainder is too large - the connection will be closed. -1 means no limits will be applied.- Parameters:
maxPayloadRemainderToSkip-- Since:
- 2.3.13
-
isPreserveHeaderCase
public boolean isPreserveHeaderCase()- Returns:
trueif header case will be preserved, otherwisefalse. Default isfalse.
-
setPreserveHeaderCase
public void setPreserveHeaderCase(boolean preserveHeaderCase) Set totrueto preserve header case. Default isfalse.- Parameters:
preserveHeaderCase-trueto preserve header case.
-
getTransferEncodings
Gets registered
TransferEncodings.- Returns:
- registered
TransferEncodings.
-
addTransferEncoding
Adds the specified
TransferEncodingto theHttpCodecFilter.- Parameters:
transferEncoding- theTransferEncodingto add
-
removeTransferEncoding
Removes the specified
TransferEncodingfrom theHttpCodecFilter.- Parameters:
transferEncoding- theTransferEncodingto remove- Returns:
trueif theTransferEncodingwas removed, otherwisefalseindicating theTransferEncodingwas not already present
-
getContentEncodings
Gets registered
ContentEncodings.- Returns:
- registered
ContentEncodings.
-
addContentEncoding
Adds the specified
ContentEncodingto theHttpCodecFilter.- Parameters:
contentEncoding- theContentEncodingto add
-
removeContentEncoding
Removes the specified
ContentEncodingfrom theHttpCodecFilter.- Parameters:
contentEncoding- theContentEncodingto remove- Returns:
trueif theContentEncodingwas removed, otherwisefalseindicating theContentEncodingwas not already present
-
isChunkingEnabled
protected boolean isChunkingEnabled()Returntrueif chunked transfer-encoding may be used.- Returns:
trueif chunked transfer-encoding may be used.- Since:
- 2.1.2
-
isRemoveHandledContentEncodingHeaders
public boolean isRemoveHandledContentEncodingHeaders()- Returns:
trueif content-encoding headers that are handled by this module should be removed from the header- Since:
- 2.3.39
- See Also:
-
setRemoveHandledContentEncodingHeaders
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.- Parameters:
removeHandledContentEncodingHeaders-trueif content-encoding headers that are handled by this module should be removed from the header- Since:
- 2.3.39
-
handleRead
public final org.glassfish.grizzly.filterchain.NextAction handleRead(org.glassfish.grizzly.filterchain.FilterChainContext ctx, HttpHeader httpHeader) throws IOException The method is called by the specific HttpCodecFilter implementation, once we have received aBuffer, which has to be transformed into HTTP packet part. Filter getsBuffer, which represents a part or complete HTTP message. As the result of "read" transformation - we will getHttpContentmessage, which will represent HTTP packet content (might be zero length content) and reference to aHttpHeader, which contains HTTP message header.- Parameters:
ctx- Request processing contexthttpHeader- the currentHttpHeader, which is being processed.- Returns:
NextAction- Throws:
IOException
-
decodeHttpPacket
protected boolean decodeHttpPacket(org.glassfish.grizzly.filterchain.FilterChainContext ctx, HttpPacketParsing httpPacket, org.glassfish.grizzly.Buffer input) -
decodeHttpPacketFromBytes
protected boolean decodeHttpPacketFromBytes(org.glassfish.grizzly.filterchain.FilterChainContext ctx, HttpPacketParsing httpPacket, org.glassfish.grizzly.Buffer inputBuffer) -
parseHeadersFromBytes
protected boolean parseHeadersFromBytes(HttpHeader httpHeader, MimeHeaders mimeHeaders, HttpCodecFilter.HeaderParsingState parsingState, byte[] input, int end) -
parseHeaderFromBytes
protected boolean parseHeaderFromBytes(HttpHeader httpHeader, MimeHeaders mimeHeaders, HttpCodecFilter.HeaderParsingState parsingState, byte[] input, int end) -
parseHeaderName
protected boolean parseHeaderName(HttpHeader httpHeader, MimeHeaders mimeHeaders, HttpCodecFilter.HeaderParsingState parsingState, byte[] input, int end) -
parseHeaderValue
protected static int parseHeaderValue(HttpHeader httpHeader, HttpCodecFilter.HeaderParsingState parsingState, byte[] input, int end) -
decodeHttpPacketFromBuffer
protected boolean decodeHttpPacketFromBuffer(org.glassfish.grizzly.filterchain.FilterChainContext ctx, HttpPacketParsing httpPacket, org.glassfish.grizzly.Buffer input) -
parseHeadersFromBuffer
protected boolean parseHeadersFromBuffer(HttpHeader httpHeader, MimeHeaders mimeHeaders, HttpCodecFilter.HeaderParsingState parsingState, org.glassfish.grizzly.Buffer input) -
parseHeaderFromBuffer
protected boolean parseHeaderFromBuffer(HttpHeader httpHeader, MimeHeaders mimeHeaders, HttpCodecFilter.HeaderParsingState parsingState, org.glassfish.grizzly.Buffer input) -
parseHeaderName
protected boolean parseHeaderName(HttpHeader httpHeader, MimeHeaders mimeHeaders, HttpCodecFilter.HeaderParsingState parsingState, org.glassfish.grizzly.Buffer input) -
parseHeaderValue
protected static int parseHeaderValue(HttpHeader httpHeader, HttpCodecFilter.HeaderParsingState parsingState, org.glassfish.grizzly.Buffer input) -
handleWrite
public org.glassfish.grizzly.filterchain.NextAction handleWrite(org.glassfish.grizzly.filterchain.FilterChainContext ctx) throws IOException The method is called, once we need to serialize aHttpPacket, which may represent HTTP packet header, content or content chunk. Filter getsHttpPacket, which represents a HTTP header, content, or content part. As the result of "write" transformation - we will getBuffer, which will represent serialized HTTP packet.- Specified by:
handleWritein interfaceorg.glassfish.grizzly.filterchain.Filter- Overrides:
handleWritein classorg.glassfish.grizzly.filterchain.BaseFilter- Parameters:
ctx- Request processing context- Returns:
NextAction- Throws:
IOException
-
onIncomingUpgrade
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).- Parameters:
ctx-httpHeader-
-
onOutgoingUpgrade
protected void onOutgoingUpgrade(org.glassfish.grizzly.filterchain.FilterChainContext ctx, HttpHeader httpHeader) -
encodeHttpPacket
protected org.glassfish.grizzly.Buffer encodeHttpPacket(org.glassfish.grizzly.filterchain.FilterChainContext ctx, HttpPacket input) -
encodeHttpPacket
protected final org.glassfish.grizzly.Buffer encodeHttpPacket(org.glassfish.grizzly.filterchain.FilterChainContext ctx, HttpHeader httpHeader, HttpContent httpContent, boolean isContentAlreadyEncoded) -
encodeKnownHeaders
protected static org.glassfish.grizzly.Buffer encodeKnownHeaders(org.glassfish.grizzly.memory.MemoryManager memoryManager, org.glassfish.grizzly.Buffer buffer, HttpHeader httpHeader) -
encodeMimeHeaders
protected static org.glassfish.grizzly.Buffer encodeMimeHeaders(org.glassfish.grizzly.memory.MemoryManager memoryManager, org.glassfish.grizzly.Buffer buffer, MimeHeaders mimeHeaders, byte[] tempEncodingBuffer) -
encodeMimeHeader
-
isSecure
protected static boolean isSecure(org.glassfish.grizzly.Connection connection) flag, which indicates whether this HttpCodecFilter is dealing with the secured HTTP packets. For this filter flag means nothing, it's just a value, which is getting set to aHttpRequestPacketorHttpResponsePacket.- Parameters:
connection-Connection- Returns:
- true, if the
Connectionis secured, or false otherwise
-
statusDropsConnection
protected static boolean statusDropsConnection(int status) Determine if we must drop the connection because of the HTTP status code. Use the same list of codes as Apache/httpd. -
getMonitoringConfig
- Specified by:
getMonitoringConfigin interfaceorg.glassfish.grizzly.monitoring.MonitoringAware<HttpProbe>
-
createJmxManagementObject
-