org.apache.commons.httpclient

Class Header

Implemented Interfaces:
Serializable

public class Header
extends NameValuePair

An HTTP header.
See Also:
Serialized Form

Constructor Summary

Header()
Default constructor.
Header(String name, String value)
Constructor with name and value
Header(String name, String value, boolean isAutogenerated)
Constructor with name and value

Method Summary

HeaderElement[]
getElements()
Returns an array of HeaderElements constructed from my value.
HeaderElement[]
getValues()
Deprecated. Use #getElements
boolean
isAutogenerated()
Returns the value of the auto-generated header flag.
String
toExternalForm()
Returns a String representation of the header.
String
toString()
Returns a String representation of the header.

Methods inherited from class org.apache.commons.httpclient.NameValuePair

equals, getName, getValue, hashCode, setName, setValue, toString

Methods inherited from class java.lang.Object

clone, equals, extends Object> getClass, finalize, hashCode, notify, notifyAll, toString, wait, wait, wait

Constructor Details

Header

public Header()
Default constructor.

Header

public Header(String name,
              String value)
Constructor with name and value
Parameters:
name - the header name
value - the header value
Usages and Demos :

View More Examples of Header(String name,String value)
   1:             response.setBodyString(s);
   2:             response.addHeader(new Header("Connection", "close"));
   3:         ...
   4:             response.addHeader(new Header("Content-Lenght", Integer.toString(s.length())));
   5:             responses.put(code, response);
   6:         }
   7:         return response;

View Full Code Here
   1:             response.setStatusLine(ver, HttpStatus.SC_OK);
   2:             response.addHeader(new Header("Connection", "close"));
   3:             response.addHeader(new Header("Set-Cookie", 
   4:                 "custno = 12345; comment=test; version=1," +
   5:                 " name=John; version=1; max-age=600; secure; domain=.apache.org"));

View Full Code Here
   1:         if (this.keepalive) {
   2:             response.addHeader(new Header("Connection", "keep-alive"));
   3:             conn.setKeepAlive(true);
   4:         ...
   5:         } else {
   6:             response.addHeader(new Header("Connection", "close"));
   7:             conn.setKeepAlive(false);
   8:         }
   9:         return response;

View Full Code Here
   1:         if (!response.containsHeader("Content-Type")) {
   2:             response.addHeader(new Header("Content-Type", "text/plain"));
   3:         }
   4:         ...
   5:                     }
   6:                     Header header = new Header("Transfer-Encoding", "chunked"); 
   7:                     response.addHeader(header);                
   8:         ...
   9:                 } else {
  10:                     Header header = new Header("Content-Length", Long.toString(len)); 
  11:                     response.setHeader(header);

View Full Code Here
   1:                 if (connheader.getValue().equalsIgnoreCase("close")) {
   2:                     request.setHeader(new Header("Connection", "close"));
   3:                 }
   4:         ...
   5:                 if (s.equalsIgnoreCase("close")) {
   6:                     response.setHeader(new Header("Proxy-Connection", "close"));
   7:                     conn.setKeepAlive(false);
   8:         ...
   9:                 if (s.equalsIgnoreCase("keep-alive")) {
  10:                     response.setHeader(new Header("Proxy-Connection", "keep-alive"));
  11:                     conn.setKeepAlive(true);

View Full Code Here

Header

public Header(String name,
              String value,
              boolean isAutogenerated)
Constructor with name and value
Parameters:
name - the header name
value - the header value
isAutogenerated - true if the header is autogenerated, false otherwise.
Since:
3.0
Usages and Demos :

View More Examples of Header(String name,String value,boolean isAutogenerated)
   1:     public void testCookieWithComma() throws Exception {
   2:         Header header = new Header("Set-Cookie", "a=b,c");
   3: 
   4:         CookieSpec cookiespec = new NetscapeDraftSpec();
   5:         Cookie[] cookies = cookiespec.parse("localhost", 80, "/", false, header);

View Full Code Here
   1:             String s = proxy ? PROXY_AUTH_RESP : WWW_AUTH_RESP;
   2:             Header header = new Header(s, auth, true);
   3:             method.addRequestHeader(header);
   4:         ...
   5:             String s = proxy ? PROXY_AUTH_RESP : WWW_AUTH_RESP;
   6:             Header header = new Header(s, auth, true);
   7:             method.addRequestHeader(header);
   8:             return true;
   9:         } else {

View Full Code Here
   1:     public void testCookieWithComma() throws Exception {
   2:         Header header = new Header("Set-Cookie", "a=b,c");
   3: 
   4:         CookieSpec cookiespec = new RFC2109Spec();
   5:         Cookie[] cookies = cookiespec.parse("localhost", 80, "/", false, header);

View Full Code Here
   1:         CookieSpec cookiespec = new RFC2965Spec();
   2:         Header header = new Header("Set-Cookie2", "a=b,c");
   3:         Cookie[] parsed = cookiespec.parse("www.domain.com", 80, "/", false, header);
   4:         assertNotNull(parsed);
   5:         assertEquals(2, parsed.length);

View Full Code Here

Method Details

getElements

public HeaderElement[] getElements()
Returns an array of HeaderElements constructed from my value.
Returns:
an array of header elements
Since:
3.0

getValues

public HeaderElement[] getValues()
            throws HttpException

Deprecated. Use #getElements

Returns an array of HeaderElements constructed from my value.
Returns:
an array of header elements
Throws:
HttpException - if the header cannot be parsed

isAutogenerated

public boolean isAutogenerated()
Returns the value of the auto-generated header flag.
Returns:
true if the header is autogenerated, false otherwise.
Since:
3.0

toExternalForm

public String toExternalForm()
Returns a String representation of the header.
Returns:
stringHEAD
Usages and Demos :

View More Examples of toExternalForm()
   1: import org.apache.commons.httpclient.ChunkedOutputStream;
   2: import org.apache.commons.httpclient.Header;
   3: import org.apache.commons.httpclient.HttpParser;
   4:         ...
   5:         while (item.hasNext()) {
   6:             Header header = (Header) item.next();
   7:         ...
   8:             writer.print(header.toExternalForm());
   9:         }
  10:         ...
  11:             Header header = (Header) item.next();
  12:             writer.print(header.toExternalForm());

View Full Code Here

toString

public String toString()
Returns a String representation of the header.
Overrides:
toString in interface NameValuePair
Returns:
stringHEAD