Top Description Inners Fields Constructors Methods
org.glassfish.grizzly.http

public abstract Class HttpCodecFilter

extends HttpBaseFilter
implements MonitoringAware<HttpProbe>
Class Inheritance
All Implemented Interfaces
org.glassfish.grizzly.monitoring.MonitoringAware
Known Direct Subclasses
org.glassfish.grizzly.http.HttpServerFilter, org.glassfish.grizzly.http.HttpClientFilter
Static Imports
org.glassfish.grizzly.http.util.HttpCodecUtils.checkEOL, .HttpCodecUtils.isSpaceOrTab, .HttpCodecUtils.put, .HttpCodecUtils.skipSpaces, org.glassfish.grizzly.utils.Charsets.ASCII_CHARSET

The org.glassfish.grizzly.filterchain.Filter, responsible for transforming Buffer into HttpPacket and vice versa in asynchronous mode. When the HttpCodecFilter is added to a org.glassfish.grizzly.filterchain.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
HttpServerFilter, HttpClientFilter

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static class
public static class

Field Summary

Modifier and TypeField and Description
private static final byte[]
protected final boolean
protected static final byte[]
CLOSE_BYTES

Close bytes.

pack-priv static final byte[]
COLON_BYTES

Colon bytes.

protected final ArraySet<ContentEncoding>
pack-priv static final byte[]
CRLF_BYTES

CRLF bytes.

public static final int
protected static final byte[]
KEEPALIVE_BYTES

Keep-alive bytes.

private static final Logger
protected final int
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 final DefaultMonitoringConfig<HttpProbe>
monitoringConfig

File cache probes

public static final String
protected boolean
private boolean
public static final String
public static final String
private final boolean
private final boolean
private final ArraySet<TransferEncoding>

Constructor Summary

AccessConstructor and Description
public
HttpCodecFilter(final boolean
true if the chunked transfer encoding should be used when no explicit content length has been set.
chunkingEnabled
,
final int
the maximum size of the HTTP message header.
maxHeadersSize
)

Constructor, which creates HttpCodecFilter instance, with the specific max header size parameter.

public
HttpCodecFilter(final boolean
true if the chunked transfer encoding should be used when no explicit content length has been set.
chunkingEnabled
,
final int
the maximum size of the HTTP message header.
maxHeadersSize
,
final Properties
the properties to be used for configuring the filter.
props
)

Constructor, which creates HttpCodecFilter instance, with the specific max header size and properties parameter.

Method Summary

Modifier and TypeMethod and Description
public void
addContentEncoding(final ContentEncoding
the ContentEncoding to add
contentEncoding
)

Adds the specified ContentEncoding to the HttpCodecFilter.

public void
addTransferEncoding(final TransferEncoding
the TransferEncoding to add
transferEncoding
)

Adds the specified TransferEncoding to the HttpCodecFilter.

private boolean
checkRemainderOverflow(final HttpHeader httpHeader, final int payloadChunkSize)

Returns: true, if payload remainder read doesn't exceed the limit

protected Object
pack-priv final HttpContent
protected boolean
decodeHttpPacket(final FilterChainContext ctx, final HttpPacketParsing httpPacket, final Buffer input)

protected boolean
decodeHttpPacketFromBuffer(final FilterChainContext ctx, final HttpPacketParsing httpPacket, final Buffer input)

protected boolean
decodeHttpPacketFromBytes(final FilterChainContext ctx, final HttpPacketParsing httpPacket, final Buffer inputBuffer)

pack-priv abstract boolean

Returns:

true, if initial line has been parsed, or false otherwise.
decodeInitialLineFromBuffer
(FilterChainContext ctx, HttpPacketParsing
HTTP packet, which is being parsed
httpPacket
,
HttpCodecFilter.HeaderParsingState
HTTP packet parsing state
parsingState
,
Buffer
input Buffer
input
)

Method is responsible for parsing initial line of HTTP message (different for HttpRequestPacket and HttpResponsePacket).

pack-priv abstract boolean

Returns:

true, if initial line has been parsed, or false otherwise.
decodeInitialLineFromBytes
(FilterChainContext ctx, HttpPacketParsing
HTTP packet, which is being parsed
httpPacket
,
HttpCodecFilter.HeaderParsingState
HTTP packet parsing state
parsingState
,
byte[]
input
input
,
int
index of the last available byte in the input array (offset is passed inside parsingState)
end
)

Method is responsible for parsing initial line of HTTP message (different for HttpRequestPacket and HttpResponsePacket).

private NextAction
decodeWithTransferEncoding(final FilterChainContext ctx, final HttpHeader httpHeader, final Buffer input, final boolean wasHeaderParsed)

pack-priv final HttpContent
encodeContent(final Connection<L> connection, HttpContent httpContent)

private static Buffer
encodeContentEncodingHeader(final MemoryManager<E extends Buffer> memoryManager, Buffer buffer, final HttpHeader httpHeader, final CacheableDataChunk name, final CacheableDataChunk value)

protected Buffer
protected final Buffer
encodeHttpPacket(final FilterChainContext ctx, final HttpHeader httpHeader, final HttpContent httpContent, final boolean isContentAlreadyEncoded)

pack-priv abstract Buffer

Returns:

result Buffer.
encodeInitialLine
(HttpPacket
HTTP packet, which is being serialized
httpPacket
,
Buffer
output Buffer
output
,
MemoryManager<E extends Buffer> memoryManager)

Method is responsible for serializing initial line of HTTP message (different for HttpRequestPacket and HttpResponsePacket).

pack-priv Buffer
encodeInitialLine(HttpPacket httpPacket, HttpStatus status, Buffer output, MemoryManager<E extends Buffer> memoryManager)

Variant of encodeInitialLine(HttpPacket, Buffer, MemoryManager) that overrides the status used in the status line, for serializing interim (1xx) responses whose status differs from the final response status.

protected static Buffer
encodeKnownHeaders(final MemoryManager<E extends Buffer> memoryManager, Buffer buffer, final HttpHeader httpHeader)

protected static Buffer
encodeMimeHeader(final MemoryManager<E extends Buffer> memoryManager, Buffer buffer, final DataChunk name, final DataChunk value, final byte[] tempBuffer, final boolean encodeLastCRLF)

protected static Buffer
encodeMimeHeaders(final MemoryManager<E extends Buffer> memoryManager, Buffer buffer, final MimeHeaders mimeHeaders, final byte[] tempEncodingBuffer)

protected static Buffer
encodeMimeHeaders(final MemoryManager<E extends Buffer> memoryManager, Buffer buffer, final MimeHeaders mimeHeaders, final byte[] tempEncodingBuffer, final boolean markSerialized)

private static void
finalizeKnownHeaderNames(final HttpHeader httpHeader, final HttpCodecFilter.HeaderParsingState parsingState, final byte[] input, final int start, final int end)

private static void
finalizeKnownHeaderNames(final HttpHeader httpHeader, final HttpCodecFilter.HeaderParsingState parsingState, final Buffer input, final int start, final int end)

private static void
finalizeKnownHeaderValues(final HttpHeader httpHeader, final HttpCodecFilter.HeaderParsingState parsingState, final byte[] input, final int start, final int end)

private static void
finalizeKnownHeaderValues(final HttpHeader httpHeader, final HttpCodecFilter.HeaderParsingState parsingState, final Buffer input, final int start, final int end)

public ContentEncoding[]

Returns:

registered ContentEncodings.
getContentEncodings
()

Gets registered ContentEncodings.

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.

public MonitoringConfig<HttpProbe>
public TransferEncoding[]

Returns:

registered TransferEncodings.
getTransferEncodings
()

Gets registered TransferEncodings.

public final NextAction

Returns:

NextAction
handleRead
(final FilterChainContext
Request processing context
ctx
,
final HttpHeader
the current HttpHeader, which is being processed.
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.

public NextAction

Returns:

NextAction
handleWrite
(final FilterChainContext
Request processing context
ctx
)

Overrides org.glassfish.grizzly.filterchain.BaseFilter.handleWrite.

Implements org.glassfish.grizzly.filterchain.Filter.handleWrite.

The method is called, once we need to serialize a HttpPacket, which may represent HTTP packet header, content or content chunk.

protected boolean

Returns:

true if chunked transfer-encoding may be used.
isChunkingEnabled
()

Return true if chunked transfer-encoding may be used.

public boolean
isPreserveHeaderCase()

Returns: true if header case will be preserved, otherwise false.

public boolean
isRemoveHandledContentEncodingHeaders()

Returns: true if content-encoding headers that are handled by this module should be removed from the header

private boolean
protected static boolean

Returns:

true, if the Connection is secured, or false otherwise
isSecure
(final Connection<L> connection)

flag, which indicates whether this HttpCodecFilter is dealing with the secured HTTP packets.

private static boolean
lookupAlias(final ContentEncoding encoding, final DataChunk aliasBuffer, final int startIdx)

private ContentEncoding
lookupContentEncoding(final DataChunk bc, final int startIdx)

protected abstract void
onHttpContentEncoded(final HttpContent
HttpContent, which represents HTTP packet header
content
,
final FilterChainContext
processing context.
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, which represents HTTP packet header
httpHeader
,
FilterChainContext
the FilterChainContext processing this request
ctx
,
Throwable
the cause of the error
t
)

Callback which is invoked when parsing an HTTP message payload fails.

protected abstract void
onHttpContentParsed(final HttpContent
request/response body content
content
,
final FilterChainContext
processing context.
ctx
)

Invoked as request/response body content has been processed by this org.glassfish.grizzly.filterchain.Filter.

protected abstract void
onHttpHeaderError(HttpHeader
HttpHeader, which represents HTTP packet header
httpHeader
,
FilterChainContext
the FilterChainContext processing this request
ctx
,
Throwable
the cause of the error
t
)

Callback which is invoked when parsing an HTTP message header fails.

protected abstract boolean

Returns:

true if an error has occurred while processing the header portion of the HTTP request, otherwise returns false.
onHttpHeaderParsed
(HttpHeader
HttpHeader, which represents parsed HTTP packet header
httpHeader
,
Buffer
Buffer the header was parsed from
buffer
,
FilterChainContext
processing context.
ctx
)

Callback invoked when the HTTP message header parsing is complete.

protected abstract void
onHttpHeadersEncoded(final HttpHeader
HttpHeader, which represents HTTP packet header
httpHeader
,
final FilterChainContext
processing context.
ctx
)

Invoked when HTTP headers have been encoded in preparation to being transmitted to the user-agent.

protected abstract void
onHttpHeadersParsed(final HttpHeader
HttpHeader, which represents HTTP packet header
httpHeader
,
final MimeHeaders
the headers portion, that has been parsed
headers
,
final FilterChainContext
processing context.
ctx
)

Invoked when HTTP headers portion comes for HttpHeader message.

protected abstract boolean

Returns:

true if an error has occurred while processing the header portion of the HTTP request, otherwise returns false.s
onHttpPacketParsed
(HttpHeader
HttpHeader, which represents parsed HTTP packet header
httpHeader
,
FilterChainContext
processing context.
ctx
)

Callback method, called when HttpPacket parsing has been completed.

protected void
onIncomingUpgrade(final FilterChainContext ctx, final HttpHeader httpHeader)

The method is called, when a peer sends an upgrade HTTP packet (either request or response).

protected abstract void
onInitialLineEncoded(final HttpHeader
HttpHeader, which represents HTTP packet header
httpHeader
,
final FilterChainContext
processing context.
ctx
)

Invoked when the initial response line has been encoded in preparation to being transmitted to the user-agent.

protected abstract void
onInitialLineParsed(final HttpHeader
HttpHeader, which represents HTTP packet header
httpHeader
,
final FilterChainContext
processing context.
ctx
)

Invoked when either the request line or status line has been parsed.

protected void
onOutgoingUpgrade(final FilterChainContext ctx, final HttpHeader httpHeader)

protected boolean
parseHeaderFromBuffer(final HttpHeader httpHeader, final MimeHeaders mimeHeaders, final HttpCodecFilter.HeaderParsingState parsingState, final Buffer input)

protected boolean
parseHeaderFromBytes(final HttpHeader httpHeader, final MimeHeaders mimeHeaders, final HttpCodecFilter.HeaderParsingState parsingState, final byte[] input, final int end)

protected int
parseHeaderName(final HttpHeader httpHeader, final MimeHeaders mimeHeaders, final HttpCodecFilter.HeaderParsingState parsingState, final byte[] input, final int end)

protected int
parseHeaderName(final HttpHeader httpHeader, final MimeHeaders mimeHeaders, final HttpCodecFilter.HeaderParsingState parsingState, final Buffer input)

protected boolean
parseHeadersFromBuffer(final HttpHeader httpHeader, final MimeHeaders mimeHeaders, final HttpCodecFilter.HeaderParsingState parsingState, final Buffer input)

protected boolean
parseHeadersFromBytes(final HttpHeader httpHeader, final MimeHeaders mimeHeaders, final HttpCodecFilter.HeaderParsingState parsingState, final byte[] input, final int end)

protected int
parseHeaderValue(final HttpHeader httpHeader, final HttpCodecFilter.HeaderParsingState parsingState, final byte[] input, final int end)

protected int
parseHeaderValue(final HttpHeader httpHeader, final HttpCodecFilter.HeaderParsingState parsingState, final Buffer input)

private ParsingResult
parseWithTransferEncoding(final FilterChainContext ctx, final HttpHeader httpHeader, final Buffer input)

public boolean

Returns:

true if the ContentEncoding was removed, otherwise false indicating the ContentEncoding was not already present
removeContentEncoding
(final ContentEncoding
the ContentEncoding to remove
contentEncoding
)

Removes the specified ContentEncoding from the HttpCodecFilter.

public boolean

Returns:

true if the TransferEncoding was removed, otherwise false indicating the TransferEncoding was not already present
removeTransferEncoding
(final TransferEncoding
the TransferEncoding to remove
transferEncoding
)

Removes the specified TransferEncoding from the HttpCodecFilter.

private Buffer
serializeWithTransferEncoding(final FilterChainContext ctx, final HttpContent httpContent, final TransferEncoding encoding)

pack-priv final void
pack-priv final void
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.

public void
setPreserveHeaderCase(boolean
true to preserve header case.
preserveHeaderCase
)

Set to true to preserve header case.

public void
setRemoveHandledContentEncodingHeaders(boolean
true if content-encoding headers that are handled by this module should be removed from the header
removeHandledContentEncodingHeaders
)

If enabled the content-encoding header for handled content-encodings is removed.

pack-priv final void
pack-priv final void
setTransferEncodingOnSerializing(final FilterChainContext ctx, final HttpHeader httpHeader, final HttpContent httpContent)

protected static boolean
statusDropsConnection(int status)

Determine if we must drop the connection because of the HTTP status code.

Inherited from org.glassfish.grizzly.http.HttpBaseFilter:
bind