|
|||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||||
java.lang.Objectcom.marringtons.net.HTTP.Header
This class provides basic support for interpreting and creating HTTP headers. HTTP requests and responses include a header that is basically a list of name/value pairs that ends in a blank line. This class can be used by client and server components to both receive and send a header.
Header header = new Header(clientSocket.getReader());
int contentLength = header.contentLength();
Request request = new Request(socket);
Header header = request.getHeader();
String accept = header.get("Accept");
header.clear();
header.add("Server", "Adept - http://adept.marringtons.com");
header.add("P3P", "CP=\"NOI?DSP?COR?CURa?TAIa?OUR?STP?PRE\"");
header.add("Cache-Control", "max-age=" + maxAge); // 1 day
writer.write(header.toString());
| Field Summary | |
boolean |
staticContent
Set true if data to send is static content. |
| Constructor Summary | |
Header()
Default initialisation. |
|
Header(BufferedReader in)
Initialise a header and read it in from a stream at the same time. |
|
| Method Summary | |
boolean |
add(String line)
Used by connection to add header values to request object. |
void |
add(String key,
int value)
Used to add arbitrary integer values to the header. |
void |
add(String key,
String value)
Used to add arbitrary string values to the header. |
void |
clear()
Clear the header of content - typically ready to load a new header. |
int |
contentLength()
Use to retrieve the length of the message content to be sent. |
void |
contentLength(int length)
Set the content length - presumably for a write. |
boolean |
exists(String key)
See if the header includes a specific entry. |
String |
get(String key)
Get a header entry - and an empty string if it doesn't exist. |
String |
get(String key,
String defaultValue)
Get a header entry - and a specified default value if it doesn't exist. |
void |
read(BufferedReader in)
Read the header, leaving the stream ready to read the body on request. |
String[] |
toArray()
Used by exec as the CGI environment. |
String |
toString()
Convert HTTP header to a viable string ready to send to the browser. |
| Methods inherited from class java.lang.Object |
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Field Detail |
public boolean staticContent
| Constructor Detail |
public Header()
public Header(BufferedReader in)
throws IOException
in - stream reader to retrieve header from.
IOException - if the stream has a problem.| Method Detail |
public boolean exists(String key)
key - to look for in header
public String get(String key)
key - to look for in header
public String get(String key,
String defaultValue)
key - to look for in headerdefaultValue - if the key does not exist.
public String[] toArray()
public boolean add(String line)
line - of the form "key: value"
public void add(String key,
String value)
key - to add to headervalue - to add for key to header
public void add(String key,
int value)
key - to add to headervalue - to add for key to header
public void read(BufferedReader in)
throws IOException
in - reader to retrieve header from server.
IOExceptionpublic String toString()
Object.toString()public void clear()
public int contentLength()
public void contentLength(int length)
length - of the http response
|
|||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||||