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:
HttpRequestPacket and HttpResponsePacket.- Author:
- Alexey Stashok
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classHttpHeader.Builder<T extends HttpHeader.Builder>HttpHeader message builder. -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected longprotected final ContentType.SettableContentTypeprotected final MimeHeadersprotected booleanprotected booleanprotected booleantrue if HTTP message payload is broken due to inappropriate Transfer-Encoding or Content-Encoding settings.protected booleanprotected booleanprotected Protocolprotected final DataChunkprotected booleanprotected final DataChunk -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected voidaddContentEncoding(ContentEncoding contentEncoding) voidAdd the HTTP mime header.voidaddHeader(String name, HeaderValue value) Add the HTTP mime header.voidAdd 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 voidFlush internal fields for special header names to the headers map.org.glassfish.grizzly.attributes.AttributeHolderprotected List<ContentEncoding>getContentEncodings(boolean isModifiable) longGet the content-length of thisHttpPacket.protected ContentTypeGet the value, of the specific HTTP mime header.Get the value, of the specific HTTP mime header.Get allMimeHeaders, associated with the HttpHeader.Returns this HttpHeader object.protected HttpPacketParsingabstract ProcessingStateGet HTTP protocol version.Get the HTTP message protocol version asDataChunk(avoiding creation of a String object).Get the HTTP message protocol version.byte[]Get theTransferEncoding, responsible for the parsing/serialization of the HTTP message contentfinal Stringfinal HttpContent.BuilderGet the HTTP message content builder.Get the HTTP message trailer-chunk builder.booleanReturns true, if thisHttpPacketcontent will be transferred in chunking mode, or false if case of fixed-length message.booleanReturntrueif chunking is allowed for this header.booleanIs this HttpHeader written? true, if this HttpHeader has been already serialized, and onlyHttpContentmessages might be serialized for thisHttpPacket.booleanReturns true, if HTTP packet payload was detected as broken due to unexpected error occurred during Transfer-Encoding or Content-Encoding processing.protected final booleanbooleanbooleanReturns true, if HTTP message, represented by this header still expects additional content basing either on content-length or chunking information.final booleanisHeader()Returns true.booleanabstract booleanReturns true, if the current HttpHeader represent HTTP request message, or false otherwise.booleanisSecure()booleanReturns 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.booleanprotected voidmakeContentLengthHeader(long defaultLength) Makes sure content-length header is present.protected voidmakeTransferEncodingHeader(String defaultValue) Makes sure transfer-encoding header is present.protected voidPropagate 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 final 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) voidSet the value, of the specific HTTP mime header.voidsetHeader(String name, HeaderValue value) Set the value, of the specific HTTP mime header.voidSet 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.final voidsetUpgrade(String upgrade) Sets the "Upgrade" header valueMethods inherited from class org.glassfish.grizzly.http.HttpPacket
isHttp
-
Field Details
-
isCommitted
protected boolean isCommitted -
headers
-
protocolC
-
parsedProtocol
-
isChunked
protected boolean isChunked -
contentLength
protected long contentLength -
contentType
-
isExpectContent
protected boolean isExpectContent -
isSkipRemainder
protected boolean isSkipRemainder -
isContentBroken
protected boolean isContentBrokentrue if HTTP message payload is broken due to inappropriate Transfer-Encoding or Content-Encoding settings. -
secure
protected boolean secure -
upgrade
-
-
Constructor Details
-
HttpHeader
public HttpHeader() -
HttpHeader
-
-
Method Details
-
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
Returns this HttpHeader object.- Specified by:
getHttpHeaderin classHttpPacket- Returns:
- this HttpHeader object.
-
getProcessingState
-
getParsingState
- Returns:
- the parsing state of this HTTP header, or null if the message is complete or shouldn't be parsed at all
-
addContentEncoding
-
getContentEncodings
-
getContentEncodings
-
isContentEncodingsSelected
protected final boolean isContentEncodingsSelected() -
setContentEncodingsSelected
protected final void setContentEncodingsSelected(boolean isContentEncodingsSelected) -
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
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
- Returns:
- the "Upgrade" header value.
-
getUpgradeDC
- Returns:
- the "Upgrade" header value.
-
setUpgrade
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
Makes sure transfer-encoding header is present.- Parameters:
defaultValue- default transfer-encoding value.
-
extractContentEncoding
Obtain content-encoding value and mark it as serialized.- Parameters:
value- container for the content-type value.
-
getCharacterEncoding
- Returns:
- the character encoding of this HTTP message.
-
setCharacterEncoding
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
- Returns:
- the content type of this HTTP message.
-
setContentType
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
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
- Returns:
ContentTypeholder
-
getHeaders
Get allMimeHeaders, associated with the HttpHeader.- Specified by:
getHeadersin interfaceMimeHeadersPacket- Returns:
- all
MimeHeaders, associated with the HttpHeader
-
getHeader
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
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
Set the value, of the specific HTTP mime header.- Specified by:
setHeaderin interfaceMimeHeadersPacket- Parameters:
name- the mime header namevalue- the mime header value
-
setHeader
Set the value, of the specific HTTP mime header.- Specified by:
setHeaderin interfaceMimeHeadersPacket- Parameters:
name- the mime header namevalue- the mime header value
-
setHeader
Set the value, of the specific HTTP mime header.- Specified by:
setHeaderin interfaceMimeHeadersPacket- Parameters:
header- the mimeHeadervalue- the mime header value
-
setHeader
Set the value, of the specific HTTP mime header.- Specified by:
setHeaderin interfaceMimeHeadersPacket- Parameters:
header- the mimeHeadervalue- the mime header value
-
addHeader
Add the HTTP mime header.- Specified by:
addHeaderin interfaceMimeHeadersPacket- Parameters:
name- the mime header namevalue- the mime header value
-
addHeader
Add the HTTP mime header.- Specified by:
addHeaderin interfaceMimeHeadersPacket- Parameters:
name- the mime header namevalue- the mime header value
-
addHeader
Add the HTTP mime header.- Specified by:
addHeaderin interfaceMimeHeadersPacket- Parameters:
header- the mimeHeadervalue- the mime header value
-
addHeader
Add the HTTP mime header.- Specified by:
addHeaderin interfaceMimeHeadersPacket- Parameters:
header- the mimeHeadervalue- the mime header value
-
containsHeader
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
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
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
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".
-
getProtocol
Get HTTP protocol version.- Returns:
Protocol.
-
setProtocol
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
Get the HTTP message content builder.- Returns:
HttpContent.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.
-