    All Packages  Class Hierarchy  This Package  Previous  Next  Index

# Class w3c.www.http.HttpMessage

    java.lang.Object
       |
       +----w3c.www.http.HttpMessage

public class HttpMessage
extends Object
implements MimeHeaderHolder, Cloneable, HTTP

The basic class for all HTTP messages, as define in the HTTP spec. This class is the base class for a number of other classes, including both the ingoing/outgoing requests and replies.

##

descriptors
EMIT_ALL
EMIT_BODY
EMIT_FOOTERS
EMIT_HEADERS
emitdate
  The date at which this message was last emitted.
factory
  The header value factory.
H_CACHE_CONTROL
H_CONNECTION
H_COOKIE
H_DATE
H_PRAGMA
H_PROTOCOL
H_PROTOCOL_INFO
H_PROTOCOL_QUERY
H_PROTOCOL_REQUEST
H_PROXY_CONNECTION
H_SET_COOKIE
H_TRANSFER_ENCODING
H_UPGRADE
H_VIA
headers
  The header value repository.
major
  The major version of this message, according to HTTP specs.
MAX_HEADERS
minor
  The minoir version of this message, according to HTTP specs.
state
  The state dictionary.
values

##

HttpMessage()
HttpMessage(MimeParser)

##

addConnection(String)
  Add the given header name to the `Connection` header.
addNoCache(String)
  Add the given header name to the `no-cache` directive.
addPragma(String)
  Add the given directive to the `Pragma` header.
addProxyConnection(String)
  Add the given header name to the `Proxy-Connection` header.
addVia(String)
  Add a via clause to the via header.
checkNoStore()
  Check the `no-store` directive of the cache control header.
checkOnlyIfCached()
  Check the `only-if-cached` directive.
delState(String)
  State management - Remove a piece of state from this request.
dump(OutputStream)
emit(OutputStream)
  Emit this message to the given output stream.
emit(OutputStream, int)
emitHeaders(OutputStream, int)
endEmit(OutputStream, int)
  This message has been emited.
enumerateHeaderDescriptions()
  Enumerate all the headers defined for that message.
enumerateHeaderDescriptions(boolean)
  Enumerate all the available headers for that message.
getCacheControl()
  Header accessor - get the cache control policy.
getClone()
  Get a clone of this HTTP message.
getConnection()
  Header accessor - get the connection header value.
getCookie()
  Get the cookies attached to that message.
getDate()
  Header accessor - get the date of this message.
getEmitDate()
  Get the date at which this message was last emitted, if ever it was.
getHeaderValue(HeaderDescription)
  Get a header value, keyed by it's header description.
getHeaderValue(int)
  Fast access to header value.
getHeaderValue(String)
  Get a header value by name.
getHeaderValue(String, HeaderValue)
  Get a header value, given its name.
getMajorVersion()
  Get the major version number of this message.
getMaxAge()
  Get the `max-age` value for the current cache control.
getMinorVersion()
  Get the minor version number of this message.
getNoCache()
  Get the `no-cache` directive of the cache control header.
getPragma()
  Header accessor - get the pragmas applicable to this message.
getProtocol()
  Get the set of protocol extensions that have been aplpied to that that message.
getProtocolInfo()
  Get the protocol extensions informations carried by this message.
getProtocolQuery()
  Get the set of protocol extensions that are queried through this message.
getProtocolRequest()
  Get the set of protocol extensions requested by this message.
getProxyConnection()
  Header accessor - get the proxy connection header value.
getSetCookie()
  Get the value of the SetCookie header.
getState(String)
  State management - Lookup the value of a state on this request.
getTransferEncoding()
  Header accessor - get the transfer encoding applying to this message.
getUpgrade()
  Header accessor - get the upgrade header of this message.
getValue(HeaderDescription)
  Get a header field value as a String.
getValue(String)
  Get a header field value as a String.
getVersion()
  Get the String identifying the HTTP version used for this message.
getVia()
  Header accessor - get the via header of this message.
hasConnection(String)
  Does the connection header include the given token ?
hasHeader(int)
  Probe this message for a defined header, fast access !
hasHeader(String)
  Probe this message for a defined header.
hasPragma(String)
  Header accessor - Check for a given pragma.
hasProxyConnection(String)
  Does the proxy connection header defines the given token.
hasState(String)
  State management - Is the given state defined for the message ?
hasTransferEncoding(String)
  Header accessor - Check for a given transfer encoding.
notifyBeginParsing(MimeParser)
  MimeHeaderHolder implementation - HTTP message about to be parsed.
notifyEndParsing(MimeParser)
  MimeHeaderHolder implementation - HTTP message parsing done.
notifyHeader(String, byte[], int, int)
  MimeHeaderHolder implementation - The MIME parser callback.
registerHeader(String, String)
registerHeader(String, String, int)
removeHeader(int)
  Remove a header, by address.
removeHeader(String)
  Remove a header, by name.
setCacheControl(HttpCacheControl)
  Header accessor - set the cache control associated with the message.
setConnection(String[])
  Header accessor - set the connection header value.
setCookie(HttpCookieList)
  Set the cookies attached to this message.
setDate(long)
  Header accessor - set the date of this message.
setHeaderValue(HeaderDescription, HeaderValue)
  Set a header value, keyed by it's header description.
setHeaderValue(int, HeaderValue)
  Fast write accessor to headers.
setHeaderValue(String, HeaderValue)
  Set a header value.
setMaxAge(int)
  Set the `max-age` value of the associated cache control.
setNoCache()
  Set the `no-cache` directive globally.
setNoCache(String[])
  Set the `no-cache` directive of the cache control header.
setNoStore(boolean)
  Set the `no-store` directive.
setOnlyIfCached(boolean)
  Set the `only-if-cached` directive.
setPragma(String[])
  Header accessor - set the pragmas applicable to this message.
setProtocol(HttpBag)
  Set the protocol extensions applied to that message.
setProtocolInfo(HttpBag)
  Attach protocol extensions informations to that message.
setProtocolQuery(HttpBag)
  Set the protocol extensions queried by that message.
setProtocolRequest(HttpBag)
  Set the protocol extensions required by this message.
setProxyConnection(String[])
  Header accessor - set the proxy connection header value.
setSetCookie(HttpSetCookieList)
  Set the value of the Set-Cookie header.
setState(String, Object)
  State management - Add a piece of state to this request.
setTransferEncoding(String[])
  Header accessor - set the transfer encoding for this message.
setUpgrade(String[])
  Header accessor - set the upgrade header of this message.
setValue(String, String)
  Define a new header field.
setVia(String[])
  Header accessor - set the Via header of this message.
startEmit(OutputStream, int)
  This message is about to be emited.

##

EMIT_HEADERS

     public static final int EMIT_HEADERS

EMIT_BODY

     public static final int EMIT_BODY

EMIT_FOOTERS

     public static final int EMIT_FOOTERS

EMIT_ALL

     public static final int EMIT_ALL

H_CACHE_CONTROL

     public static int H_CACHE_CONTROL

H_CONNECTION

     public static int H_CONNECTION

H_PROXY_CONNECTION

     public static int H_PROXY_CONNECTION

H_DATE

     public static int H_DATE

H_PRAGMA

     public static int H_PRAGMA

H_TRANSFER_ENCODING

     public static int H_TRANSFER_ENCODING

H_UPGRADE

     public static int H_UPGRADE

H_VIA

     public static int H_VIA

H_PROTOCOL

     public static int H_PROTOCOL

H_PROTOCOL_REQUEST

     public static int H_PROTOCOL_REQUEST

H_PROTOCOL_INFO

     public static int H_PROTOCOL_INFO

H_PROTOCOL_QUERY

     public static int H_PROTOCOL_QUERY

H_SET_COOKIE

     public static int H_SET_COOKIE

H_COOKIE

     public static int H_COOKIE

MAX_HEADERS

     public static int MAX_HEADERS

factory

     protected static Hashtable factory

  The header value factory.

headers

     protected Dictionary headers

  The header value repository. At this time, I am using this quite inefficient scheme, but the API have been carefully designed to enable a more efficient implementation.

major

     protected short major

  The major version of this message, according to HTTP specs.

minor

     protected short minor

  The minoir version of this message, according to HTTP specs.

emitdate

     protected long emitdate

  The date at which this message was last emitted.

state

     protected ArrayDictionary state

  The state dictionary.

values

     protected HeaderValue values[]

descriptors

     protected static HeaderDescription descriptors[]

##

HttpMessage

     public HttpMessage(MimeParser parser)

HttpMessage

     public HttpMessage()

##

registerHeader

     protected static final void registerHeader(String name,
                                                String cls)

registerHeader

     protected static final void registerHeader(String name,
                                                String c,
                                                int i)

getHeaderValue

     public HeaderValue getHeaderValue(String name,
                                       HeaderValue def)

  Get a header value, given its name.

  Parameters:
    name - The name of the field whose value is to be fetched.
    def - The default value if the field is undefined.

getHeaderValue

     public final HeaderValue getHeaderValue(String name)

  Get a header value by name.

  Parameters:
    name - The header's name.
  Returns:
    The value of the header, as a String, or null if undefined.

getHeaderValue

     public final HeaderValue getHeaderValue(int idx)

  Fast access to header value.

  This method provides a very fast access to pre-defined header values. You can use it on all headers that have an access token.

  Parameters:
    idx - The token of the header to access.
  Returns:
    An instance of `HeaderValue` or null if undefined.

setHeaderValue

     public void setHeaderValue(String name,
                                HeaderValue value)

  Set a header value.

  Parameters:
    name - The name of the header to define.
    value - It's HeaderValue.

getHeaderValue

     public HeaderValue getHeaderValue(HeaderDescription d)

  Get a header value, keyed by it's header description. This is usefull when enumerating headers, by the mean of `enumerateHeaderDescriptions`.

  Parameters:
    d - The header description.
  Returns:
    A HeaderValue instance, if the header is defined, null otherwise.

setHeaderValue

     public void setHeaderValue(HeaderDescription d,
                                HeaderValue v)

  Set a header value, keyed by it's header description.

  Parameters:
    d - The header description.
    v - The HeaderValue instance, or null to reset the header value.

setHeaderValue

     public final void setHeaderValue(int idx,
                                      HeaderValue value)

  Fast write accessor to headers.

  This method provides a very fast write access to header values. It can be used with any of the headers that have a pre-defined access token.

  Parameters:
    idx - The access token of the header's to write to.
    value - The new header value.

removeHeader

     public void removeHeader(String name)

  Remove a header, by name.

  Parameters:
    name - The name of the header to remove.

removeHeader

     public final void removeHeader(int idx)

  Remove a header, by address. A fast version of the above.

  Parameters:
    idx - The index of the header to remove.

enumerateHeaderDescriptions

     public Enumeration enumerateHeaderDescriptions(boolean all)

  Enumerate all the available headers for that message. This method returns an enumeration of HeaderDescription instances, which you can then use to access most efficiently header values.

  Parameters:
    all - If true the enumeration will cover all headers (even the ones that are not defined for that message) otherwise, it will cover only defined headers.
  Returns:
    An enumeration.

enumerateHeaderDescriptions

     public Enumeration enumerateHeaderDescriptions()

  Enumerate all the headers defined for that message. This method returns an enumeration of HeaderDescription instances, which you can then use to access most efficiently header values.

  Returns:
    An enumeration.

setState

     public void setState(String name,
                          Object value)

  State management - Add a piece of state to this request. If the piece of state already exists, it is overriden by the new value.

  Parameters:
    name - The name of the piece of state to define.
    value - It's corresponding value, or null to reset the value.

getState

     public Object getState(String name)

  State management - Lookup the value of a state on this request.

  Parameters:
    name - The name of the piece of state to look for.
  Returns:
    An object, if the piece of state is defined, null otherwise.

delState

     public void delState(String name)

  State management - Remove a piece of state from this request.

  Parameters:
    name - The name of the piece of state to remove.

hasState

     public boolean hasState(String name)

  State management - Is the given state defined for the message ?

  Returns:
    A boolean true if the state is defined, false otherwise.

getClone

     public HttpMessage getClone()

  Get a clone of this HTTP message.

  Returns:
    An HttpMessage, of the class of the message receiver.

getValue

     public String getValue(String name)

  Get a header field value as a String.

  Parameters:
    name - The name of the header.
  Returns:
    A String giving the header value, or null if undefined.

getValue

     public String getValue(HeaderDescription d)

  Get a header field value as a String.

  Parameters:
    d - The header description.
  Returns:
    The String value for the given header, or null if undefined.

setValue

     public void setValue(String name,
                          String strval)

  Define a new header field.

  Parameters:
    name - The name of the header to be defined or reset.
    value - It's String value, or null to reset the value.

hasHeader

     public boolean hasHeader(String name)

  Probe this message for a defined header.

  Parameters:
    name - The name of the header to check.
  Returns:
    true if the header is defined, false otherwise.

hasHeader

     public boolean hasHeader(int idx)

  Probe this message for a defined header, fast access !

  Parameters:
    idx - The index of the well-known header to check.
  Returns:
    true if the header is defined, false otherwise.

notifyHeader

     public void notifyHeader(String name,
                              byte buf[],
                              int off,
                              int len)

  MimeHeaderHolder implementation - The MIME parser callback. This method is called if the HttpMessage is created by parsing an input stream. Each time the MIME parser detects a new header field, it calls back this method.

  Parameters:
    name - The name of the header that has been encountered.
    buf - The buffer containing the header value.
    off - The offset of the header value in the above buffer.
    len - The length of the header value in the above buffer.

notifyBeginParsing

     public boolean notifyBeginParsing(MimeParser parser) throws HttpParserException, IOException

  MimeHeaderHolder implementation - HTTP message about to be parsed. No further action is required at this point (we do not distinguish between request or reply here). The MIME parsing is to continue normally so we return false.

  Returns:
    Always false to conotinue the MIME parsing.

notifyEndParsing

     public void notifyEndParsing(MimeParser parser) throws HttpParserException, IOException

  MimeHeaderHolder implementation - HTTP message parsing done. Nothing special to be done here, return straight.

startEmit

     protected void startEmit(OutputStream out,
                              int what) throws IOException

  This message is about to be emited. Take any appropriate actions.

endEmit

     protected void endEmit(OutputStream out,
                            int what) throws IOException

  This message has been emited. Take any appropriate action.

emitHeaders

     protected void emitHeaders(OutputStream out,
                                int what) throws IOException

dump

     public void dump(OutputStream out)

emit

     public void emit(OutputStream out) throws IOException

  Emit this message to the given output stream. This methods emits the given message to the stream, after invoking the `startEmit` method. Once the whole message has been emited, the `endEmit` method is called back.

  Parameters:
    out - The output stream to emit the message to.
  Throws: IOException
    If the message couldn't be emited to the given stream, due to IO errors.

emit

     public void emit(OutputStream out,
                      int what) throws IOException

setCacheControl

     public void setCacheControl(HttpCacheControl control)

  Header accessor - set the cache control associated with the message. This method should not be used in general, it's much more preferable to use the various cache control accessors available.

  Parameters:
    control - The cache control policy, or null to reset the value.

getCacheControl

     public HttpCacheControl getCacheControl()

  Header accessor - get the cache control policy.

  Returns:
    The current cache control policy, or null if undefined.

setMaxAge

     public void setMaxAge(int maxage)

  Set the `max-age` value of the associated cache control. This method hides as much as possible, the difference between HTTP/1.1 max-age, and HTTP/1.0 expires headers. It will set only the appropriate one.

  Parameters:
    maxage - The max-age value, or -1 to reset the value.

getMaxAge

     public int getMaxAge()

  Get the `max-age` value for the current cache control.

  Returns:
    The max age value, as an integer, or -1 if undefined.

getNoCache

     public String[] getNoCache()

  Get the `no-cache` directive of the cache control header.

  Returns:
    A list of token (potentially empty) encoded as an array of String (with 0 length if empty), or null if undefined.

setNoCache

     public void setNoCache(String nocache[])

  Set the `no-cache` directive of the cache control header.

  Parameters:
    nocache - A list of headers name encoded as an array of String (of length possibly 0), or null to reset the value.

setNoCache

     public void setNoCache()

  Set the `no-cache` directive globally.

addNoCache

     public void addNoCache(String name)

  Add the given header name to the `no-cache` directive.

  Parameters:
    name - The header name to add there.

checkNoStore

     public boolean checkNoStore()

  Check the `no-store` directive of the cache control header.

  Returns:
    A boolean true if set, false otherwise.

setNoStore

     public void setNoStore(boolean onoff)

  Set the `no-store` directive.

  Parameters:
    onoff - Turn it on or off.

checkOnlyIfCached

     public boolean checkOnlyIfCached()

  Check the `only-if-cached` directive.

  Returns:
    A boolean, true if the directive is set, false otherwise.

setOnlyIfCached

     public void setOnlyIfCached(boolean onoff)

  Set the `only-if-cached` directive.

  Parameters:
    onoff - Turn it on or off.

setConnection

     public void setConnection(String tokens[])

  Header accessor - set the connection header value.

  Parameters:
    tokens - The connection tokens as a String array, or null to reset the value.

getConnection

     public String[] getConnection()

  Header accessor - get the connection header value.

  Returns:
    The tokens of the connection header, as a String array, or null if undefined.

addConnection

     public void addConnection(String name)

  Add the given header name to the `Connection` header.

  Parameters:
    name - The name of the header to add to the `Connection` header.

hasConnection

     public boolean hasConnection(String tok)

  Does the connection header include the given token ?

  Returns:
    A boolean.

setProxyConnection

     public void setProxyConnection(String tokens[])

  Header accessor - set the proxy connection header value.

  Parameters:
    tokens - The connection tokens as a String array, or null to reset the value.

addProxyConnection

     public void addProxyConnection(String name)

  Add the given header name to the `Proxy-Connection` header.

  Parameters:
    name - The name of the header to add to the `Proxy-Connection` header.

getProxyConnection

     public String[] getProxyConnection()

  Header accessor - get the proxy connection header value.

  Returns:
    The tokens of the connection header, as a String array, or null if undefined.

hasProxyConnection

     public boolean hasProxyConnection(String tok)

  Does the proxy connection header defines the given token.

  Parameters:
    tok - The token to check for.
  Returns:
    A boolean.

setDate

     public void setDate(long date)

  Header accessor - set the date of this message.

  Parameters:
    date - The date of the message, following Java runtime conventions (number of milliseconds since epoch), or -1 to reset the value.

getDate

     public long getDate()

  Header accessor - get the date of this message.

  Returns:
    A long giving the date of this message, following the Java runtime convention (milliseconds since epoch), or -1 if undefined.

setPragma

     public void setPragma(String tokens[])

  Header accessor - set the pragmas applicable to this message.

  Parameters:
    tokens - The pragma tokens as a String array, or null to reset the value.

getPragma

     public String[] getPragma()

  Header accessor - get the pragmas applicable to this message.

  Returns:
    The pragma tokens applicable to this message, encoded as a String array, or null if undefined.

hasPragma

     public boolean hasPragma(String pragma)

  Header accessor - Check for a given pragma.

  Parameters:
    pragma - The pragma to check for.
  Returns:
    A boolean true if this pragma is set, false otherwise.

addPragma

     public void addPragma(String name)

  Add the given directive to the `Pragma` header.

  Parameters:
    name - The name of the directive to add to the `Pragma` header.

setTransferEncoding

     public void setTransferEncoding(String tokens[])

  Header accessor - set the transfer encoding for this message. This just sets the transfer encoding, it is up to the rest of the application to make sure that the encoding is actually applied at emiting time.

  Parameters:
    tokens - The transfer encoding tokens as a String array, or null to reset the value.

getTransferEncoding

     public String[] getTransferEncoding()

  Header accessor - get the transfer encoding applying to this message.

  Returns:
    The list of encoding tokens, as a String array, or null if undefined.

hasTransferEncoding

     public boolean hasTransferEncoding(String encoding)

  Header accessor - Check for a given transfer encoding.

  Parameters:
    encoding - The pragma to check for.
  Returns:
    A boolean true if this encoding is set, false otherwise.

setUpgrade

     public void setUpgrade(String products[])

  Header accessor - set the upgrade header of this message.

  Parameters:
    products - An array of products you want this message to carry or null to reset the value.

getUpgrade

     public String[] getUpgrade()

  Header accessor - get the upgrade header of this message.

  Returns:
    A list of products, encoded as an array of String or null if undefined.

setVia

     public void setVia(String vias[])

  Header accessor - set the Via header of this message.

  Parameters:
    vias - The hops to be placed in the `Via` header, or null to reset the value.

getVia

     public String[] getVia()

  Header accessor - get the via header of this message.

  Returns:
    A Via array describing each hop of the message, or null if undefined.

addVia

     public void addVia(String via)

  Add a via clause to the via header.

  Parameters:
    via - The new via clause.

getProtocol

     public HttpBag getProtocol()

  Get the set of protocol extensions that have been aplpied to that that message.

  Returns:
    A bag containing the description of the protocol extensions applied to that message, or null.

setProtocol

     public void setProtocol(HttpBag bag)

  Set the protocol extensions applied to that message.

  Parameters:
    protocols - A bag instance, describing the protocol extensions applied to the message, or null to reset previous value.

getProtocolRequest

     public HttpBag getProtocolRequest()

  Get the set of protocol extensions requested by this message.

  Returns:
    A bag containing the description of the protocol extensions requested by this message, or null.

setProtocolRequest

     public void setProtocolRequest(HttpBag bag)

  Set the protocol extensions required by this message.

  Parameters:
    protocols - A bag instance, describing the protocol extensions required by the message, or null to reset previous value.

getProtocolInfo

     public HttpBag getProtocolInfo()

  Get the protocol extensions informations carried by this message.

  Returns:
    A bag containing the description of the protocol extensions informations carried by that message, or null.

setProtocolInfo

     public void setProtocolInfo(HttpBag bag)

  Attach protocol extensions informations to that message.

  Parameters:
    protocols - A bag instance, describing the protocol extensions informations to attach to the message, or null to reset previous value.

getProtocolQuery

     public HttpBag getProtocolQuery()

  Get the set of protocol extensions that are queried through this message.

  Returns:
    A bag containing the description of the protocol extensions queried by that message, or null.

setProtocolQuery

     public void setProtocolQuery(HttpBag bag)

  Set the protocol extensions queried by that message.

  Parameters:
    protocols - A bag instance, describing the protocol extensions queried by the message, or null to reset previous value.

getSetCookie

     public HttpSetCookieList getSetCookie()

  Get the value of the SetCookie header.

  Returns:
    AN HttpSetCookie instance, or null if undefined.

setSetCookie

     public void setSetCookie(HttpSetCookieList setcookie)

  Set the value of the Set-Cookie header.

  Parameters:
    setcookies - The HttpSetCookie value.

getCookie

     public HttpCookieList getCookie()

  Get the cookies attached to that message.

  Returns:
    An instance of HttpCookie holding the list of available cookies, or null if undefined.

setCookie

     public void setCookie(HttpCookieList cookie)

  Set the cookies attached to this message.

  Parameters:
    cookies - The HttpCookie instance describing the cookies, or null to reset value.

getVersion

     public String getVersion()

  Get the String identifying the HTTP version used for this message.

  Returns:
    A String identifying the protocol version.

getMajorVersion

     public short getMajorVersion()

  Get the major version number of this message. This method returns the major version that the caller should use to drive message processing. It may not match the version number actually emitted on the wire, which is computed by the API itself.

  Returns:
    A ninteger giving the major version number.

getMinorVersion

     public short getMinorVersion()

  Get the minor version number of this message. This method returns the minor version that the caller should use to drive message processing. It may not match the minor version number emitted on the wire, which is computed by the API itself.

  Returns:
    An integer giving the minor version number.

getEmitDate

     public long getEmitDate()

  Get the date at which this message was last emitted, if ever it was.

  Returns:
    The date, in milliseconds since Java epoch at which this message was emitted, or -1 if the message was never emitted.

    All Packages  Class Hierarchy  This Package  Previous  Next  Index