org.glassfish.grizzly.http
Class HttpHeader

java.lang.Object
  extended by org.glassfish.grizzly.http.HttpPacket
      extended by org.glassfish.grizzly.http.HttpHeader
All Implemented Interfaces:
AttributeStorage, Cacheable, MimeHeadersPacket
Direct Known Subclasses:
HttpRequestPacket, HttpResponsePacket

public abstract class HttpHeader
extends HttpPacket
implements MimeHeadersPacket, AttributeStorage

HttpPacket, which represents HTTP message header. There are 2 subtypes of this class: HttpRequestPacket and HttpResponsePacket.

Author:
Alexey Stashok
See Also:
HttpRequestPacket, HttpResponsePacket

Nested Class Summary
static class HttpHeader.Builder<T extends HttpHeader.Builder>
          HttpHeader message builder.
 
Field Summary
protected  String characterEncoding
           
protected  boolean charsetSet
          Has the charset been explicitly set.
protected  long contentLength
           
protected  String contentType
           
protected  boolean contentTypeParsed
           
protected  MimeHeaders headers
           
protected  boolean isChunked
           
protected  boolean isCommitted
           
protected  boolean isExpectContent
           
protected  boolean isSkipRemainder
           
protected  Protocol parsedProtocol
           
protected  DataChunk protocolC
           
protected  String quotedCharsetValue
           
protected  boolean secure
           
protected  DataChunk upgrade
           
 
Constructor Summary
HttpHeader()
           
 
Method Summary
protected  void addContentEncoding(ContentEncoding contentEncoding)
           
 void addHeader(String name, String value)
          Add the HTTP mime header.
 boolean containsHeader(String name)
          Returns true, if the mime header with the specific name is present among the HttpHeader mime headers, or false otherwise.
protected  void extractContentEncoding(DataChunk value)
          Obtain content-encoding value and mark it as serialized.
protected  void extractContentType(DataChunk dc)
          Obtain content-type value and mark it as serialized.
 AttributeHolder getAttributes()
          
 String getCharacterEncoding()
           
 List<ContentEncoding> getContentEncodings()
           
protected  List<ContentEncoding> getContentEncodings(boolean isModifiable)
           
 long getContentLength()
          Get the content-length of this HttpPacket.
 String getContentType()
           
protected  byte[] getDefaultContentType()
           
 String getHeader(String name)
          Get the value, of the specific HTTP mime header.
 MimeHeaders getHeaders()
          Get all MimeHeaders, associated with the HttpHeader.
abstract  ProcessingState getProcessingState()
           
 Protocol getProtocol()
          Get HTTP protocol version.
 DataChunk getProtocolDC()
          Get the HTTP message protocol version as DataChunk (avoiding creation of a String object).
 String getProtocolString()
          Get the HTTP message protocol version.
 TransferEncoding getTransferEncoding()
          Get the TransferEncoding, responsible for the parsing/serialization of the HTTP message content
 String getUpgrade()
           
 DataChunk getUpgradeDC()
           
 HttpContent.Builder httpContentBuilder()
          Get the HTTP message content builder.
 HttpTrailer.Builder httpTrailerBuilder()
          Get the HTTP message trailer-chunk builder.
 boolean isChunked()
          Returns true, if this HttpPacket content will be transferred in chunking mode, or false if case of fixed-length message.
 boolean isCommitted()
          Is this HttpHeader written? true, if this HttpHeader has been already serialized, and only HttpContent messages might be serialized for this HttpPacket.
 boolean isContentTypeSet()
           
 boolean isExpectContent()
          Returns true, if HTTP message, represented by this header still expects additional content basing either on content-length or chunking information.
 boolean isHeader()
          Returns true.
abstract  boolean isRequest()
          Returns true, if the current HttpHeader represent HTTP request message, or false otherwise.
 boolean isSecure()
           
 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 this Connection.
protected  void makeContentLengthHeader(Connection c, long defaultLength)
          Makes sure content-length header is present.
protected  void makeTransferEncodingHeader(String defaultValue)
          Makes sure transfer-encoding header is present.
protected  void makeUpgradeHeader()
           
 void recycle()
          
protected  void reset()
          Reset the internal state.
 void setCharacterEncoding(String charset)
          Set the character encoding of this HTTP message.
 void setChunked(boolean isChunked)
          Set true, if this HttpPacket content will be transferred in chunking mode, or false if case of fixed-length message.
 void setCommitted(boolean isCommitted)
          Is this HttpHeader written? true, if this HttpHeader has been already serialized, and only HttpContent messages might be serialized for this HttpPacket.
 void setContentLength(int len)
          Set the lenth of this HTTP message.
 void setContentLengthLong(long contentLength)
          Set the content-length of this HttpPacket.
 void setContentType(String type)
          Sets the content type.
protected  void setDefaultContentType(byte[] defaultContentType)
           
protected  void setExpectContent(boolean isExpectContent)
           
 void setHeader(String name, String value)
          Set the value, of the specific HTTP mime header.
 void setProtocol(Protocol protocol)
          Set the HTTP message protocol version.
protected  void setSecure(boolean secure)
          Sets the secure status of this HTTP message.
 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 this Connection.
protected  void setTransferEncoding(TransferEncoding transferEncoding)
          Set the TransferEncoding, responsible for the parsing/serialization of the HTTP message content.
 void setUpgrade(String upgrade)
           
 
Methods inherited from class org.glassfish.grizzly.http.HttpPacket
isHttp
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

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

characterEncoding

protected String characterEncoding

quotedCharsetValue

protected String quotedCharsetValue

charsetSet

protected boolean charsetSet
Has the charset been explicitly set.


contentTypeParsed

protected boolean contentTypeParsed

contentType

protected String contentType

isExpectContent

protected boolean isExpectContent

isSkipRemainder

protected boolean isSkipRemainder

secure

protected boolean secure

upgrade

protected final DataChunk upgrade
Constructor Detail

HttpHeader

public HttpHeader()
Method Detail

getAttributes

public AttributeHolder getAttributes()

Specified by:
getAttributes in interface 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:
isHeader in class HttpPacket
Returns:
true.

getProcessingState

public abstract ProcessingState getProcessingState()

addContentEncoding

protected void addContentEncoding(ContentEncoding contentEncoding)

getContentEncodings

protected List<ContentEncoding> getContentEncodings(boolean isModifiable)

getContentEncodings

public List<ContentEncoding> getContentEncodings()

getTransferEncoding

public TransferEncoding getTransferEncoding()
Get the TransferEncoding, 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 the TransferEncoding, responsible for the parsing/serialization of the HTTP message content.

Parameters:
transferEncoding - the TransferEncoding, responsible for the parsing/serialization of the HTTP message content.

isChunked

public boolean isChunked()
Returns true, if this HttpPacket content will be transferred in chunking mode, or false if case of fixed-length message.

Returns:
true, if this HttpPacket content will be transferred in chunking mode, or false if case of fixed-length message.

setChunked

public void setChunked(boolean isChunked)
Set true, if this HttpPacket content will be transferred in chunking mode, or false if case of fixed-length message.

Parameters:
isChunked - true, if this HttpPacket content 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

protected 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 this Connection. 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 this Connection.

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 this Connection.

getUpgrade

public String getUpgrade()

getUpgradeDC

public DataChunk getUpgradeDC()

setUpgrade

public void setUpgrade(String upgrade)

makeUpgradeHeader

protected void makeUpgradeHeader()

makeContentLengthHeader

protected void makeContentLengthHeader(Connection c,
                                       long defaultLength)
Makes sure content-length header is present.

Parameters:
defaultLength - default content-length value.

getContentLength

public long getContentLength()
Get the content-length of this HttpPacket. 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 lenth of this HTTP message.

Parameters:
len - the length of this HTTP message.

setContentLengthLong

public void setContentLengthLong(long contentLength)
Set the content-length of this HttpPacket. Applicable only in case of fixed-length HTTP message.

Parameters:
contentLength - the content-length of this HttpPacket. 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 only HttpContent messages might be serialized for this HttpPacket.

Returns:
true, if this HttpHeader has been already serialized, and only HttpContent messages might be serialized for this HttpPacket.

setCommitted

public void setCommitted(boolean isCommitted)
Is this HttpHeader written? true, if this HttpHeader has been already serialized, and only HttpContent messages might be serialized for this HttpPacket.

Parameters:
isCommitted - true, if this HttpHeader has been already serialized, and only HttpContent messages might be serialized for this HttpPacket.

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.

extractContentType

protected void extractContentType(DataChunk dc)
Obtain content-type value and mark it as serialized.

Parameters:
dc - container for the content-type value.

isContentTypeSet

public boolean isContentTypeSet()
Returns:
true if a content type has been set.

getContentType

public String getContentType()
Returns:
the content type of this HTTP message.

setContentType

public void setContentType(String type)
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:
type - the content type

getHeaders

public MimeHeaders getHeaders()
Get all MimeHeaders, associated with the HttpHeader.

Specified by:
getHeaders in interface MimeHeadersPacket
Returns:
all MimeHeaders, associated with the HttpHeader.

getHeader

public String getHeader(String name)
Get the value, of the specific HTTP mime header.

Specified by:
getHeader in interface MimeHeadersPacket
Parameters:
name - the mime header name.
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:
setHeader in interface MimeHeadersPacket
Parameters:
name - the mime header name.
value - the mime header value.

addHeader

public void addHeader(String name,
                      String value)
Add the HTTP mime header.

Specified by:
addHeader in interface MimeHeadersPacket
Parameters:
name - the mime header name.
value - 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:
containsHeader in interface MimeHeadersPacket
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.

getProtocolDC

public DataChunk getProtocolDC()
Get the HTTP message protocol version as DataChunk (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".

getProtocol

public Protocol getProtocol()
Get HTTP protocol version.

Returns:
Protocol.

setProtocol

public void setProtocol(Protocol protocol)
Set the HTTP message protocol version.

Parameters:
protocol - Protocol

isSecure

public boolean isSecure()
Returns:
true if this HTTP message is being transmitted in a secure fashion, otherwise returns false.

setSecure

protected void setSecure(boolean secure)
Sets the secure status of this HTTP message.

Parameters:
secure - true if secure, otherwise false.

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:
recycle in interface Cacheable

getDefaultContentType

protected byte[] getDefaultContentType()

setDefaultContentType

protected void setDefaultContentType(byte[] defaultContentType)


Copyright © 2011 Oracle Corpration. All Rights Reserved.