public abstract class HttpMessage extends Object
Modifier and Type | Class and Description |
---|---|
private static class |
HttpMessage.HeaderPropertyKey
This inner class represents a string that can be used as hash key that behaves case in-sensitive.
|
Constructor and Description |
---|
HttpMessage()
The constructor.
|
Modifier and Type | Method and Description |
---|---|
void |
appendHeaderProperty(String name,
String appendValue)
This method appends the given
value to the HTTP header-property with the given name . |
void |
appendHeaderProperty(String name,
String appendValue,
String separator)
This method appends the given
value to the HTTP header-property with the given name . |
protected Object |
createHeaderNameHash(String name)
This method converts the header property to an hash key.
|
int |
getCacheControlMaxAge()
This method gets the
maximum age (lease time) in seconds. |
String |
getContentEncoding()
This method gets the
content-encoding . |
Long |
getContentLength()
This method gets the
content-length . |
String |
getContentType()
This method gets the
content-type . |
String |
getDate()
This method gets the
date . |
String |
getHeaderProperty(String name)
This method gets the property with the given
name from the header of this HTTP message. |
String |
getHeaderPropertyAttribute(String name,
String attributeName)
This method gets a single attribute of the property with the given
name from the header of this HTTP
message. |
String |
getVersion()
This method gets the HTTP version to use.
|
void |
serialize(StringBuffer buffer)
This method serializes this HTTP-message to the given string buffer.
|
void |
setCacheControlMaxAge(int seconds)
This method sets the
maximum age (lease time) in seconds. |
void |
setContentEncoding(String encoding)
This method sets the
content-encoding . |
void |
setContentLength(long contentLength)
This method sets the
content-length . |
void |
setContentType(String contentType)
This method sets the
content-type . |
void |
setDate(String date)
This method sets the
date . |
void |
setHeaderProperty(String name,
String value)
This method sets the HTTP header-property with the given
name to the given value . |
void |
setHeaderPropertyAttribute(String name,
String attributeName,
String attributeValue)
This method sets a single attribute of the property with the given
name in the header of this HTTP message. |
void |
setVersion(String httpVersion)
This method sets the HTTP version to use.
|
String |
toString() |
protected abstract void |
writeFirstLine(StringBuffer buffer)
This method writes the first line (request-line or status-line) of the HTTP message.
|
public static final String VERSION_PREFIX
public static final String VERSION_0_9
public static final String VERSION_1_0
public static final String VERSION_1_1
public static final String HEADER_PROPERTY_CONTENT_ENCODING
header-property
Content-Encoding
.public static final String HEADER_PROPERTY_CONTENT_LENGTH
header-property
Content-Length
.public static final String HEADER_PROPERTY_CONTENT_TYPE
header-property
Content-Type
.public static final String HEADER_PROPERTY_CACHE_CONTROL
header-property
Cache-Control
.public static final String HEADER_PROPERTY_DATE
header-property
Date
.public static final String HEADER_PROPERTY_EXPIRES
header-property
Expires
.public static final String HEADER_PROPERTY_FROM
header-property
From
.public static final String HEADER_PROPERTY_IF_MODIFIED_SINCE
header-property
If-Modified-Since
.public static final String HEADER_PROPERTY_LAST_MODIFIED
header-property
Last-Modified
.public static final String HEADER_PROPERTY_LOCATION
header-property
Location
.public static final String HEADER_PROPERTY_PRAGMA
header-property
Pragma
.public static final String HEADER_PROPERTY_REFERER
header-property
Referer
.public static final String HEADER_PROPERTY_SERVER
header-property
Server
.public static final String HEADER_PROPERTY_USER_AGENT
header-property
User-Agent
.public static final String HEADER_PROPERTY_WWW_AUTHENTICATE
header-property
WWW-Authenticate
.public static final String HEADER_PROPERTY_HOST
header-property
Host
.public static final String HEADER_ATTRIBUTE_MAX_AGE
header-property
max-age
.protected static final String CRLF
protected static final CharFilter CHAR_FILTER_WHITELIST_COMMA_OR_SEMICOLON
protected static final CharFilter CHAR_FILTER_BLACKLIST_COMMA_OR_SEMICOLON
private String version
public String getVersion()
VERSION_1_0
,
VERSION_1_1
public void setVersion(String httpVersion)
httpVersion
- the HTTP version to set.protected Object createHeaderNameHash(String name)
string-representation
is
case in-sensitive equal
to the given name
. Additionally it needs to
have compliant implementations for equals
and hashCode
.
name
is NOT modified while
getHeaderProperty(String)
acts case in-sensitive.name
- is the header-name
to convert.name
.public String getHeaderProperty(String name)
name
from the header of this HTTP message.name
- is the name of the requested property.null
if NOT set.public void setHeaderPropertyAttribute(String name, String attributeName, String attributeValue)
name
in the header of this HTTP message.
name
- is the name of the property to manipulate.attributeName
- is the name of the attribute to set.attributeValue
- is the value of the attribute or the empty string ("") if the attribute is just a flag.public String getHeaderPropertyAttribute(String name, String attributeName)
name
from the header of this HTTP
message. Cache-Control
may have the value
no-cache,no-store,max-age=0
. Then the following code snipplet would return "0":
getHeaderPropertyAttribute
("Cache-Control"
,"max-age"
)
name
- is the name of the requested property.attributeName
- the name of the requested attribute.null
if the property is NOT set or does NOT contain the
attribute. If the property is set but has no value, the empty string ("") is returned.public void setHeaderProperty(String name, String value)
name
to the given value
.name
- is the name of the property to set.value
- is the value of the property to set.appendHeaderProperty(String, String)
public void appendHeaderProperty(String name, String appendValue)
value
to the HTTP header-property with the given name
.name
- is the name of the property to append to.appendValue
- is the value to append to the header-property.appendHeaderProperty(String, String, String)
public void appendHeaderProperty(String name, String appendValue, String separator)
value
to the HTTP header-property with the given name
. If the
header-property is NOT yet set, this method behaves like setHeaderProperty
(name, appendValue).name
- is the name of the property to append to.appendValue
- is the value to append to the header-property.separator
- if NOT null
and the header property is already set, this string will be appended after the
current value and before the given appendValue
.public String getContentType()
content-type
.null
if NOT set.public void setContentType(String contentType)
content-type
.contentType
- is the content-type to set.public Long getContentLength()
content-length
.null
if NOT set.public void setContentLength(long contentLength)
content-length
.contentLength
- is the content-length to set. It should be a non-negative value.public String getContentEncoding()
content-encoding
.null
if NOT set.public void setContentEncoding(String encoding)
content-encoding
.encoding
- is the content-encoding to set.public void setCacheControlMaxAge(int seconds)
maximum age
(lease time) in seconds. seconds
- is the max-age in seconds.public int getCacheControlMaxAge()
maximum age
(lease time) in seconds.-1
if the max-age is NOT set (properly).public String getDate()
date
.
TODO: implement HTTP date parsernull
if NOT set.public void setDate(String date)
date
.
TODO: implement HTTP date formatterdate
- is the date to set.protected abstract void writeFirstLine(StringBuffer buffer)
buffer
- is the string-buffer where to append the first line.public void serialize(StringBuffer buffer)
buffer
- is the string buffer where to append this HTTP-message to.Copyright © 2001–2016 mmm-Team. All rights reserved.