Package org.glassfish.grizzly.http
Class HttpHeader
- java.lang.Object
-
- org.glassfish.grizzly.http.HttpPacket
-
- org.glassfish.grizzly.http.HttpHeader
-
- All Implemented Interfaces:
org.glassfish.grizzly.attributes.AttributeStorage,org.glassfish.grizzly.Cacheable,MimeHeadersPacket
- Direct Known Subclasses:
HttpRequestPacket,HttpResponsePacket
public abstract class HttpHeader extends HttpPacket implements MimeHeadersPacket, org.glassfish.grizzly.attributes.AttributeStorage
HttpPacket, which represents HTTP message header. There are 2 subtypes of this class:HttpRequestPacketandHttpResponsePacket.- Author:
- Alexey Stashok
- See Also:
HttpRequestPacket,HttpResponsePacket
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classHttpHeader.Builder<T extends HttpHeader.Builder>HttpHeader message builder.
-
Field Summary
Fields Modifier and Type Field Description protected longcontentLengthprotected ContentType.SettableContentTypecontentTypeprotected MimeHeadersheadersprotected booleanisChunkedprotected booleanisCommittedprotected booleanisContentBrokentrue if HTTP message payload is broken due to inappropriate Transfer-Encoding or Content-Encoding settings.protected booleanisExpectContentprotected booleanisSkipRemainderprotected ProtocolparsedProtocolprotected DataChunkprotocolCprotected booleansecureprotected DataChunkupgrade
-
Constructor Summary
Constructors Modifier Constructor Description HttpHeader()protectedHttpHeader(MimeHeaders headers)
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected voidaddContentEncoding(ContentEncoding contentEncoding)voidaddHeader(String name, String value)Add the HTTP mime header.voidaddHeader(String name, HeaderValue value)Add the HTTP mime header.voidaddHeader(Header header, String value)Add the HTTP mime header.voidaddHeader(Header header, HeaderValue value)Add the HTTP mime header.booleancontainsHeader(String name)Returns true, if the mime header with the specific name is present among the HttpHeader mime headers, or false otherwise.booleancontainsHeader(Header header)Returns true, if the mimeHeaderis present among the HttpHeader mime headers, otherwise returns false.protected voidextractContentEncoding(DataChunk value)Obtain content-encoding value and mark it as serialized.protected voidflushSpecialHeaders()Flush internal fields for special header names to the headers map.org.glassfish.grizzly.attributes.AttributeHoldergetAttributes()StringgetCharacterEncoding()List<ContentEncoding>getContentEncodings()protected List<ContentEncoding>getContentEncodings(boolean isModifiable)longgetContentLength()Get the content-length of thisHttpPacket.StringgetContentType()protected ContentTypegetContentTypeHolder()StringgetHeader(String name)Get the value, of the specific HTTP mime header.StringgetHeader(Header header)Get the value, of the specific HTTP mime header.MimeHeadersgetHeaders()Get allMimeHeaders, associated with the HttpHeader.HttpHeadergetHttpHeader()Returns this HttpHeader object.protected HttpPacketParsinggetParsingState()abstract ProcessingStategetProcessingState()ProtocolgetProtocol()Get HTTP protocol version.DataChunkgetProtocolDC()Get the HTTP message protocol version asDataChunk(avoiding creation of a String object).StringgetProtocolString()Get the HTTP message protocol version.byte[]getTempHeaderEncodingBuffer()TransferEncodinggetTransferEncoding()Get theTransferEncoding, responsible for the parsing/serialization of the HTTP message contentStringgetUpgrade()DataChunkgetUpgradeDC()HttpContent.BuilderhttpContentBuilder()Get the HTTP message content builder.HttpTrailer.BuilderhttpTrailerBuilder()Get the HTTP message trailer-chunk builder.booleanisChunked()Returns true, if thisHttpPacketcontent will be transferred in chunking mode, or false if case of fixed-length message.booleanisChunkingAllowed()Returntrueif chunking is allowed for this header.booleanisCommitted()Is this HttpHeader written? true, if this HttpHeader has been already serialized, and onlyHttpContentmessages might be serialized for thisHttpPacket.booleanisContentBroken()Returns true, if HTTP packet payload was detected as broken due to unexpected error occurred during Transfer-Encoding or Content-Encoding processing.protected booleanisContentEncodingsSelected()booleanisContentTypeSet()booleanisExpectContent()Returns true, if HTTP message, represented by this header still expects additional content basing either on content-length or chunking information.booleanisHeader()Returns true.booleanisIgnoreContentModifiers()abstract booleanisRequest()Returns true, if the current HttpHeader represent HTTP request message, or false otherwise.booleanisSecure()booleanisSkipRemainder()Returns true, if either application or HTTP core part is not interested in parsing the rest of this HTTP message content and waits for the next HTTP message to come on thisConnection.booleanisUpgrade()protected voidmakeContentLengthHeader(long defaultLength)Makes sure content-length header is present.protected voidmakeTransferEncodingHeader(String defaultValue)Makes sure transfer-encoding header is present.protected voidmakeUpgradeHeader()Propagate the "Upgrade" value to headers.voidrecycle()protected voidreset()Reset the internal state.voidsetCharacterEncoding(String charset)Set the character encoding of this HTTP message.voidsetChunked(boolean isChunked)Set true, if thisHttpPacketcontent will be transferred in chunking mode, or false if case of fixed-length message.voidsetChunkingAllowed(boolean chunkingAllowed)Indicate whether or not chunking may be used by this header.voidsetCommitted(boolean isCommitted)Is this HttpHeader written? true, if this HttpHeader has been already serialized, and onlyHttpContentmessages might be serialized for thisHttpPacket.voidsetContentBroken(boolean isBroken)Set flag, which is set to true, means that HTTP packet payload was detected as broken due to unexpected error occurred during Transfer-Encoding or Content-Encoding processing.protected voidsetContentEncodingsSelected(boolean isContentEncodingsSelected)voidsetContentLength(int len)Set the length of this HTTP message.voidsetContentLengthLong(long contentLength)Set the content-length of thisHttpPacket.voidsetContentType(String contentType)Sets the content type.voidsetContentType(ContentType contentType)Sets the content type.voidsetExpectContent(boolean isExpectContent)voidsetHeader(String name, String value)Set the value, of the specific HTTP mime header.voidsetHeader(String name, HeaderValue value)Set the value, of the specific HTTP mime header.voidsetHeader(Header header, String value)Set the value, of the specific HTTP mime header.voidsetHeader(Header header, HeaderValue value)Set the value, of the specific HTTP mime header.voidsetIgnoreContentModifiers(boolean isIgnoreContentModifiers)Set true if parser has to ignore "Transfer-Encoding" and "Content-Encoding" headers and act as none of them were specified.voidsetProtocol(Protocol protocol)Set the HTTP message protocol version.voidsetSecure(boolean secure)Sets the secure status of this HTTP message.voidsetSkipRemainder(boolean isSkipRemainder)Set flag, which is set to true, means that we're not interested in parsing the rest of this HTTP message content and wait for the next HTTP message to come on thisConnection.protected voidsetTransferEncoding(TransferEncoding transferEncoding)Set theTransferEncoding, responsible for the parsing/serialization of the HTTP message content.voidsetUpgrade(String upgrade)Sets the "Upgrade" header value-
Methods inherited from class org.glassfish.grizzly.http.HttpPacket
isHttp
-
-
-
-
Field Detail
-
isCommitted
protected boolean isCommitted
-
headers
protected final MimeHeaders headers
-
protocolC
protected final DataChunk protocolC
-
parsedProtocol
protected Protocol parsedProtocol
-
isChunked
protected boolean isChunked
-
contentLength
protected long contentLength
-
contentType
protected final ContentType.SettableContentType contentType
-
isExpectContent
protected boolean isExpectContent
-
isSkipRemainder
protected boolean isSkipRemainder
-
isContentBroken
protected boolean isContentBroken
true if HTTP message payload is broken due to inappropriate Transfer-Encoding or Content-Encoding settings.
-
secure
protected boolean secure
-
upgrade
protected final DataChunk upgrade
-
-
Constructor Detail
-
HttpHeader
public HttpHeader()
-
HttpHeader
protected HttpHeader(MimeHeaders headers)
-
-
Method Detail
-
getAttributes
public org.glassfish.grizzly.attributes.AttributeHolder getAttributes()
- Specified by:
getAttributesin interfaceorg.glassfish.grizzly.attributes.AttributeStorage
-
isRequest
public abstract boolean isRequest()
Returns true, if the current HttpHeader represent HTTP request message, or false otherwise.- Returns:
- true, if the current HttpHeader represent HTTP request message, or false otherwise.
-
isHeader
public final boolean isHeader()
Returns true.- Specified by:
isHeaderin classHttpPacket- Returns:
- true.
-
getHttpHeader
public HttpHeader getHttpHeader()
Returns this HttpHeader object.- Specified by:
getHttpHeaderin classHttpPacket- Returns:
- this HttpHeader object.
-
getProcessingState
public abstract ProcessingState getProcessingState()
-
getParsingState
protected HttpPacketParsing getParsingState()
- Returns:
- the parsing state of this HTTP header, or null if the message is complete or shouldn't be parsed at all
-
addContentEncoding
protected void addContentEncoding(ContentEncoding contentEncoding)
-
getContentEncodings
protected List<ContentEncoding> getContentEncodings(boolean isModifiable)
-
getContentEncodings
public List<ContentEncoding> getContentEncodings()
-
isContentEncodingsSelected
protected final boolean isContentEncodingsSelected()
-
setContentEncodingsSelected
protected final void setContentEncodingsSelected(boolean isContentEncodingsSelected)
-
getTransferEncoding
public TransferEncoding getTransferEncoding()
Get theTransferEncoding, responsible for the parsing/serialization of the HTTP message content- Returns:
- the
TransferEncoding, responsible for the parsing/serialization of the HTTP message content
-
setTransferEncoding
protected void setTransferEncoding(TransferEncoding transferEncoding)
Set theTransferEncoding, responsible for the parsing/serialization of the HTTP message content.- Parameters:
transferEncoding- theTransferEncoding, responsible for the parsing/serialization of the HTTP message content.
-
isChunked
public boolean isChunked()
Returns true, if thisHttpPacketcontent will be transferred in chunking mode, or false if case of fixed-length message.- Returns:
- true, if this
HttpPacketcontent will be transferred in chunking mode, or false if case of fixed-length message.
-
setChunked
public void setChunked(boolean isChunked)
Set true, if thisHttpPacketcontent will be transferred in chunking mode, or false if case of fixed-length message. NOTE: If the protocol version of this header is 1.0 or older, chunking will be disabled regardless of the value passed.- Parameters:
isChunked- true, if thisHttpPacketcontent will be transferred in chunking mode, or false if case of fixed-length message.
-
isExpectContent
public boolean isExpectContent()
Returns true, if HTTP message, represented by this header still expects additional content basing either on content-length or chunking information. false is returned if content no additional content data is expected. Note: this method could be used only when we parse the HTTP message- Returns:
- true, if HTTP message, represented by this header still expects additional content basing either on content-length or chunking information. false is returned if content no additional content data is expected.
-
setExpectContent
public void setExpectContent(boolean isExpectContent)
-
isSkipRemainder
public boolean isSkipRemainder()
Returns true, if either application or HTTP core part is not interested in parsing the rest of this HTTP message content and waits for the next HTTP message to come on thisConnection. Otherwise returns false.- Returns:
- true, if either application or HTTP core part is not interested in parsing the rest of this HTTP
message content and waits for the next HTTP message to come on this
Connection. Otherwise returns false.
-
setSkipRemainder
public void setSkipRemainder(boolean isSkipRemainder)
Set flag, which is set to true, means that we're not interested in parsing the rest of this HTTP message content and wait for the next HTTP message to come on thisConnection.- Parameters:
isSkipRemainder- true means that we're not interested in parsing the rest of this HTTP message content and wait for the next HTTP message to come on thisConnection.
-
isContentBroken
public boolean isContentBroken()
Returns true, if HTTP packet payload was detected as broken due to unexpected error occurred during Transfer-Encoding or Content-Encoding processing. Otherwise returns false.- Returns:
- true, if HTTP packet payload was detected as broken due to unexpected error occurred during Transfer-Encoding or Content-Encoding processing. Otherwise returns false.
-
setContentBroken
public void setContentBroken(boolean isBroken)
Set flag, which is set to true, means that HTTP packet payload was detected as broken due to unexpected error occurred during Transfer-Encoding or Content-Encoding processing.- Parameters:
isBroken- true, means that HTTP packet payload was detected as broken due to unexpected error occurred during Transfer-Encoding or Content-Encoding processing.
-
getUpgrade
public final String getUpgrade()
- Returns:
- the "Upgrade" header value.
-
getUpgradeDC
public DataChunk getUpgradeDC()
- Returns:
- the "Upgrade" header value.
-
setUpgrade
public final void setUpgrade(String upgrade)
Sets the "Upgrade" header value- Parameters:
upgrade-
-
isUpgrade
public boolean isUpgrade()
- Returns:
trueif this header represents an HTTP upgrade, otherwisefalse.- Since:
- 2.3.29
-
makeUpgradeHeader
protected void makeUpgradeHeader()
Propagate the "Upgrade" value to headers.
-
isIgnoreContentModifiers
public boolean isIgnoreContentModifiers()
- Returns:
- true if parser has to ignore "Transfer-Encoding" and "Content-Encoding" headers and act as none of them were specified.
-
setIgnoreContentModifiers
public void setIgnoreContentModifiers(boolean isIgnoreContentModifiers)
Set true if parser has to ignore "Transfer-Encoding" and "Content-Encoding" headers and act as none of them were specified.- Parameters:
isIgnoreContentModifiers-
-
makeContentLengthHeader
protected void makeContentLengthHeader(long defaultLength)
Makes sure content-length header is present.- Parameters:
defaultLength- default content-length value.
-
getContentLength
public long getContentLength()
Get the content-length of thisHttpPacket. Applicable only in case of fixed-length HTTP message.- Returns:
- the content-length of this
HttpPacket. Applicable only in case of fixed-length HTTP message.
-
setContentLength
public void setContentLength(int len)
Set the length of this HTTP message.- Parameters:
len- the length of this HTTP message.
-
setContentLengthLong
public void setContentLengthLong(long contentLength)
Set the content-length of thisHttpPacket. Applicable only in case of fixed-length HTTP message.- Parameters:
contentLength- the content-length of thisHttpPacket. Applicable only in case of fixed-length HTTP message.
-
isCommitted
public boolean isCommitted()
Is this HttpHeader written? true, if this HttpHeader has been already serialized, and onlyHttpContentmessages might be serialized for thisHttpPacket.- Returns:
- true, if this HttpHeader has been already serialized, and only
HttpContentmessages might be serialized for thisHttpPacket.
-
setCommitted
public void setCommitted(boolean isCommitted)
Is this HttpHeader written? true, if this HttpHeader has been already serialized, and onlyHttpContentmessages might be serialized for thisHttpPacket.- Parameters:
isCommitted- true, if this HttpHeader has been already serialized, and onlyHttpContentmessages might be serialized for thisHttpPacket.
-
makeTransferEncodingHeader
protected void makeTransferEncodingHeader(String defaultValue)
Makes sure transfer-encoding header is present.- Parameters:
defaultValue- default transfer-encoding value.
-
extractContentEncoding
protected void extractContentEncoding(DataChunk value)
Obtain content-encoding value and mark it as serialized.- Parameters:
value- container for the content-type value.
-
getCharacterEncoding
public String getCharacterEncoding()
- Returns:
- the character encoding of this HTTP message.
-
setCharacterEncoding
public void setCharacterEncoding(String charset)
Set the character encoding of this HTTP message.- Parameters:
charset- the encoding.
-
isChunkingAllowed
public boolean isChunkingAllowed()
Returntrueif chunking is allowed for this header.- Returns:
trueif chunking is allowed for this header.- Since:
- 3.0
-
setChunkingAllowed
public void setChunkingAllowed(boolean chunkingAllowed)
Indicate whether or not chunking may be used by this header.- Parameters:
chunkingAllowed-trueif chunked transfer-encoding is allowed, otherwise returnsfalse.- Since:
- 3.0
-
isContentTypeSet
public boolean isContentTypeSet()
- Returns:
trueif a content type has been set.
-
getContentType
public String getContentType()
- Returns:
- the content type of this HTTP message.
-
setContentType
public void setContentType(String contentType)
Sets the content type. This method must preserve any charset that may already have been set via a call to request/response.setContentType(), request/response.setLocale(), or request/response.setCharacterEncoding().- Parameters:
contentType- the content type
-
setContentType
public void setContentType(ContentType contentType)
Sets the content type. This method must preserve any charset that may already have been set via a call to request/response.setContentType(), request/response.setLocale(), or request/response.setCharacterEncoding(). This method copies the passed contentType state into this ContentType.- Parameters:
contentType- the content type
-
getContentTypeHolder
protected ContentType getContentTypeHolder()
- Returns:
ContentTypeholder
-
getHeaders
public MimeHeaders getHeaders()
Get allMimeHeaders, associated with the HttpHeader.- Specified by:
getHeadersin interfaceMimeHeadersPacket- Returns:
- all
MimeHeaders, associated with the HttpHeader
-
getHeader
public String getHeader(String name)
Get the value, of the specific HTTP mime header.- Specified by:
getHeaderin interfaceMimeHeadersPacket- Parameters:
name- the mime header name- Returns:
- the value, of the specific HTTP mime header
-
getHeader
public String getHeader(Header header)
Get the value, of the specific HTTP mime header.- Specified by:
getHeaderin interfaceMimeHeadersPacket- Parameters:
header- the mimeHeader- Returns:
- the value, of the specific HTTP mime header
-
setHeader
public void setHeader(String name, String value)
Set the value, of the specific HTTP mime header.- Specified by:
setHeaderin interfaceMimeHeadersPacket- Parameters:
name- the mime header namevalue- the mime header value
-
setHeader
public void setHeader(String name, HeaderValue value)
Set the value, of the specific HTTP mime header.- Specified by:
setHeaderin interfaceMimeHeadersPacket- Parameters:
name- the mime header namevalue- the mime header value
-
setHeader
public void setHeader(Header header, String value)
Set the value, of the specific HTTP mime header.- Specified by:
setHeaderin interfaceMimeHeadersPacket- Parameters:
header- the mimeHeadervalue- the mime header value
-
setHeader
public void setHeader(Header header, HeaderValue value)
Set the value, of the specific HTTP mime header.- Specified by:
setHeaderin interfaceMimeHeadersPacket- Parameters:
header- the mimeHeadervalue- the mime header value
-
addHeader
public void addHeader(String name, String value)
Add the HTTP mime header.- Specified by:
addHeaderin interfaceMimeHeadersPacket- Parameters:
name- the mime header namevalue- the mime header value
-
addHeader
public void addHeader(String name, HeaderValue value)
Add the HTTP mime header.- Specified by:
addHeaderin interfaceMimeHeadersPacket- Parameters:
name- the mime header namevalue- the mime header value
-
addHeader
public void addHeader(Header header, String value)
Add the HTTP mime header.- Specified by:
addHeaderin interfaceMimeHeadersPacket- Parameters:
header- the mimeHeadervalue- the mime header value
-
addHeader
public void addHeader(Header header, HeaderValue value)
Add the HTTP mime header.- Specified by:
addHeaderin interfaceMimeHeadersPacket- Parameters:
header- the mimeHeadervalue- the mime header value
-
containsHeader
public boolean containsHeader(String name)
Returns true, if the mime header with the specific name is present among the HttpHeader mime headers, or false otherwise.- Specified by:
containsHeaderin interfaceMimeHeadersPacket- Parameters:
name- the mime header name- Returns:
- true, if the mime header with the specific name is present among the HttpHeader mime headers, or false otherwise
-
containsHeader
public boolean containsHeader(Header header)
Returns true, if the mimeHeaderis present among the HttpHeader mime headers, otherwise returns false.- Specified by:
containsHeaderin interfaceMimeHeadersPacket- Parameters:
header- the mimeHeader- Returns:
- true, if the mime
Headeris present among the HttpHeader mime headers, otherwise returns false
-
getProtocolDC
public DataChunk getProtocolDC()
Get the HTTP message protocol version asDataChunk(avoiding creation of a String object). The result format is "HTTP/1.x".- Returns:
- the HTTP message protocol version as
DataChunk(avoiding creation of a String object). The result format is "HTTP/1.x".
-
getProtocolString
public String getProtocolString()
Get the HTTP message protocol version. The result format is "HTTP/1.x".- Returns:
- the HTTP message protocol version. The result format is "HTTP/1.x".
-
setProtocol
public void setProtocol(Protocol protocol)
Set the HTTP message protocol version.- Parameters:
protocol-Protocol
-
isSecure
public boolean isSecure()
- Returns:
trueif this HTTP message is being transmitted in a secure fashion, otherwise returnsfalse.
-
setSecure
public void setSecure(boolean secure)
Sets the secure status of this HTTP message.- Parameters:
secure-trueif secure, otherwisefalse.
-
httpContentBuilder
public final HttpContent.Builder httpContentBuilder()
Get the HTTP message content builder.- Returns:
HttpContent.Builder.
-
httpTrailerBuilder
public HttpTrailer.Builder httpTrailerBuilder()
Get the HTTP message trailer-chunk builder.- Returns:
HttpTrailer.Builder.
-
reset
protected void reset()
Reset the internal state.
-
recycle
public void recycle()
- Specified by:
recyclein interfaceorg.glassfish.grizzly.Cacheable
-
getTempHeaderEncodingBuffer
public byte[] getTempHeaderEncodingBuffer()
-
flushSpecialHeaders
protected void flushSpecialHeaders()
Flush internal fields for special header names to the headers map.
-
-