org.glassfish.grizzly.http
Class HttpHeader

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

public abstract class HttpHeader
extends Object
implements HttpPacket, 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 charEncoding
           
protected  boolean charEncodingParsed
           
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  BufferChunk protocolBC
           
protected  boolean secure
           
protected  BufferChunk 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(BufferChunk value)
          Obtain content-encoding value and mark it as serialized.
protected  void extractContentType(BufferChunk bc)
          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()
           
 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.
 BufferChunk getProtocolBC()
          Get the HTTP message protocol version as BufferChunk (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()
           
 BufferChunk getUpgradeBC()
           
 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 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(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 enc)
          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 isCommited)
          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 setContentLength(long contentLength)
          Set the content-length of this HttpPacket.
 void setContentType(String type)
          Set the content type of this HTTP message.
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 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

protocolBC

protected final BufferChunk protocolBC

parsedProtocol

protected Protocol parsedProtocol

isChunked

protected boolean isChunked

contentLength

protected long contentLength

charEncoding

protected String charEncoding

charEncodingParsed

protected boolean charEncodingParsed

contentTypeParsed

protected boolean contentTypeParsed

contentType

protected String contentType

isExpectContent

protected boolean isExpectContent

isSkipRemainder

protected boolean isSkipRemainder

secure

protected boolean secure

upgrade

protected final BufferChunk 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 interface 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()

getUpgradeBC

public BufferChunk getUpgradeBC()

setUpgrade

public void setUpgrade(String upgrade)

makeUpgradeHeader

protected void makeUpgradeHeader()

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

setContentLength

public void setContentLength(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 isCommited)
Is this HttpHeader written? true, if this HttpHeader has been already serialized, and only HttpContent messages might be serialized for this HttpPacket.

Parameters:
isCommited - 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(BufferChunk 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 enc)
Set the character encoding of this HTTP message.

Parameters:
enc - the encoding.

extractContentType

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

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

getContentType

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

setContentType

public void setContentType(String type)
Set the content type of this HTTP message.

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.

getProtocolBC

public BufferChunk getProtocolBC()
Get the HTTP message protocol version as BufferChunk (avoiding creation of a String object). The result format is "HTTP/1.x".

Returns:
the HTTP message protocol version as BufferChunk (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


Copyright © 2010 Oracle Corpration. All Rights Reserved.