Adding JMCR-Stable version
[Benchmarks_CSolver.git] / JMCR-Stable / real-world application / jigsaw / src / org / w3c / www / http / HttpRequestMessage.java
diff --git a/JMCR-Stable/real-world application/jigsaw/src/org/w3c/www/http/HttpRequestMessage.java b/JMCR-Stable/real-world application/jigsaw/src/org/w3c/www/http/HttpRequestMessage.java
new file mode 100644 (file)
index 0000000..9775d23
--- /dev/null
@@ -0,0 +1,882 @@
+// HttpRequestMessage.java\r
+// $Id: HttpRequestMessage.java,v 1.1 2010/06/15 12:19:45 smhuang Exp $\r
+// (c) COPYRIGHT MIT and INRIA, 1996.\r
+// Please first read the full copyright statement in file COPYRIGHT.html\r
+\r
+package org.w3c.www.http;\r
+\r
+import java.io.IOException;\r
+import java.io.OutputStream;\r
+import java.net.URL;\r
+\r
+import org.w3c.www.mime.MimeParser;\r
+import org.w3c.www.mime.MimeParserException;\r
+\r
+public class HttpRequestMessage extends HttpEntityMessage {\r
+    // HTTP Request message well-known headers\r
+    public static int H_ACCEPT              = 31;\r
+    public static int H_ACCEPT_CHARSET      = 32;\r
+    public static int H_ACCEPT_ENCODING     = 33;\r
+    public static int H_ACCEPT_LANGUAGE     = 34;\r
+    public static int H_AUTHORIZATION       = 35;\r
+    public static int H_EXPECT              = 36;\r
+    public static int H_FROM                = 37;\r
+    public static int H_HOST                = 38;\r
+    public static int H_IF_MODIFIED_SINCE   = 39;\r
+    public static int H_IF_MATCH            = 40;\r
+    public static int H_IF_NONE_MATCH       = 41;\r
+    public static int H_IF_RANGE            = 42;\r
+    public static int H_IF_UNMODIFIED_SINCE = 43;\r
+    public static int H_MAX_FORWARDS        = 44;\r
+    public static int H_PROXY_AUTHORIZATION = 45;\r
+    public static int H_RANGE               = 46;\r
+    public static int H_REFERER             = 47;\r
+    public static int H_TE                  = 48;\r
+    public static int H_USER_AGENT          = 49;\r
+\r
+    static {\r
+      registerHeader("Accept"\r
+                    , "org.w3c.www.http.HttpAcceptList"\r
+                    , H_ACCEPT);\r
+      registerHeader("Accept-Charset"\r
+                    , "org.w3c.www.http.HttpAcceptCharsetList"\r
+                    , H_ACCEPT_CHARSET);\r
+      registerHeader("Accept-Encoding"\r
+                    , "org.w3c.www.http.HttpAcceptEncodingList"\r
+                    , H_ACCEPT_ENCODING);\r
+      registerHeader("Accept-Language"\r
+                    , "org.w3c.www.http.HttpAcceptLanguageList"\r
+                    , H_ACCEPT_LANGUAGE);\r
+      registerHeader("Authorization"\r
+                    , "org.w3c.www.http.HttpCredential"\r
+                    , H_AUTHORIZATION);\r
+      registerHeader("From"\r
+                    , "org.w3c.www.http.HttpString"\r
+                    , H_FROM);\r
+      registerHeader("Host"\r
+                    , "org.w3c.www.http.HttpString"\r
+                    , H_HOST);\r
+      registerHeader("If-Modified-Since"\r
+                    , "org.w3c.www.http.HttpDate"\r
+                    , H_IF_MODIFIED_SINCE);\r
+      registerHeader("If-Match"\r
+                    , "org.w3c.www.http.HttpEntityTagList"\r
+                    , H_IF_MATCH);\r
+      registerHeader("If-None-Match"\r
+                    , "org.w3c.www.http.HttpEntityTagList"\r
+                    , H_IF_NONE_MATCH);\r
+      registerHeader("If-Range"\r
+                    , "org.w3c.www.http.HttpEntityTag"\r
+                    , H_IF_RANGE);\r
+      registerHeader("If-Unmodified-Since"\r
+                    , "org.w3c.www.http.HttpDate"\r
+                    , H_IF_UNMODIFIED_SINCE);\r
+      registerHeader("Max-Forwards"\r
+                    , "org.w3c.www.http.HttpInteger"\r
+                    , H_MAX_FORWARDS);\r
+      registerHeader("Proxy-Authorization"\r
+                    , "org.w3c.www.http.HttpCredential"\r
+                    , H_PROXY_AUTHORIZATION);\r
+      registerHeader("Range"\r
+                    , "org.w3c.www.http.HttpRangeList"\r
+                    , H_RANGE);\r
+      registerHeader("Referer"\r
+                    , "org.w3c.www.http.HttpString"\r
+                    , H_REFERER);\r
+      registerHeader("User-Agent"\r
+                    , "org.w3c.www.http.HttpString"\r
+                    , H_USER_AGENT);\r
+      registerHeader("Expect"\r
+                    , "org.w3c.www.http.HttpString"\r
+                    , H_EXPECT);\r
+      registerHeader("TE"\r
+                    ,  "org.w3c.www.http.HttpAcceptEncodingList"\r
+                    , H_TE);\r
+    }\r
+\r
+    /**\r
+     * The method to execute on the target resource.\r
+     */\r
+    protected String method = "GET".intern();\r
+    /**\r
+     * The target resource, identified by its URL.\r
+     */\r
+    protected URL    url    = null;\r
+    /**\r
+     * The proxy to use for that request, if any.\r
+     */\r
+    protected URL proxy = null;\r
+\r
+    protected String sProxy = null;\r
+\r
+    /**\r
+     * This message is about to be emited, emit the request-line first !\r
+     * @param out The output stream to emit the request to.\r
+     * @exception IOException If some IO error occured while emiting the\r
+     * request.\r
+     */\r
+\r
+    protected void startEmit(OutputStream out, int what) \r
+        throws IOException\r
+    {\r
+       if ((what & EMIT_HEADERS) != EMIT_HEADERS)\r
+           return ;\r
+       // I am not sure (at all) whether this belongs here or in some subclass\r
+       if ((major >= 1) && ! hasHeader(H_HOST)) {\r
+           String h = \r
+               ((((url.getPort()==80) && \r
+                  url.getProtocol().equalsIgnoreCase("http")) || \r
+                 ((url.getPort()==443) && \r
+                  url.getProtocol().equalsIgnoreCase("https"))||\r
+                 (url.getPort() == -1))\r
+                ? url.getHost()\r
+                : url.getHost() + ":" + url.getPort());\r
+           setHeaderValue(H_HOST, HttpFactory.makeString(h));\r
+       }\r
+       // Emit the request line:\r
+       HttpBuffer buf = new HttpBuffer();\r
+       buf.append(method);\r
+       buf.append(' ');\r
+       if ( proxy != null ) {\r
+           buf.append(url.toExternalForm());\r
+       } else {\r
+           String sUrl = url.getFile();\r
+           // as to jdk1.4 getFile can be "" in that case\r
+           // we can use it when method = OPTIONS\r
+           if (sUrl.length() == 0) {\r
+               if (method == HTTP.OPTIONS) {\r
+                   buf.append('*');\r
+               } else {\r
+                   buf.append('/');\r
+               }\r
+           } else {\r
+               buf.append(sUrl);\r
+           }\r
+       }\r
+       buf.append(' ');\r
+       buf.append(getVersion());\r
+       buf.append('\r');\r
+       buf.append('\n');\r
+       buf.emit(out);\r
+    }\r
+\r
+    public void dump(OutputStream out) {\r
+       // Dump the reply status line first, and then the headers\r
+       try {\r
+           startEmit(out, EMIT_HEADERS);\r
+       } catch (Exception ex) {\r
+       }\r
+       super.dump(out);\r
+    }\r
+\r
+    /**\r
+     * @return A boolean <strong>true</strong> if the MIME parser should stop\r
+     * parsing, <strong>false</strong> otherwise.\r
+     * @exception IOException If some IO error occured while reading the\r
+     * stream.\r
+     * @exception HttpParserException if parsing failed.\r
+     */\r
+    public boolean notifyBeginParsing(MimeParser parser)\r
+       throws HttpParserException, IOException\r
+    {\r
+       // Append the whole reply line in some buffer:\r
+       HttpBuffer buf = new HttpBuffer();\r
+       int        ch  = parser.read();\r
+       // A present for Netscape !\r
+       while((ch == '\r') || (ch == '\n')) {\r
+           ch = parser.read();\r
+       }\r
+    loop:\r
+       while (true) {\r
+           switch(ch) {\r
+             case -1:\r
+                 throw new HttpParserException("End Of File");\r
+             case '\r':\r
+                 if ((ch = parser.read()) != '\n')\r
+                     parser.unread(ch);\r
+                 break loop;\r
+             case '\n':\r
+                 break loop;\r
+             default:\r
+                 buf.append(ch);\r
+           }\r
+           ch = parser.read();\r
+       }\r
+       // Parse the bufer into HTTP version and status code\r
+       byte       line[] = buf.getByteCopy();\r
+       ParseState ps     = new ParseState();\r
+       ps.ioff      = 0;\r
+       ps.bufend    = line.length;\r
+       ps.separator = (byte) ' ';\r
+       // Get the method name:\r
+       if ( HttpParser.nextItem(line, ps) < 0 ) {\r
+           throw new RuntimeException("Bad request, no method !");\r
+       }\r
+       setMethod(ps.toString(line));\r
+       // Get the URL path, or full URL\r
+       if ( HttpParser.nextItem(line, ps) < 0 ) {\r
+           throw new RuntimeException("Bad request, no URL !");\r
+       }\r
+       setTarget(ps.toString(line));\r
+       // Get the version numbers:\r
+       HttpParser.skipSpaces(line, ps);\r
+       if ( ps.ioff + 5 < ps.bufend ) {\r
+           ps.ioff += 5;\r
+           ps.separator = (byte) '.';\r
+           this.major = (short) HttpParser.parseInt(line, ps);\r
+           ps.prepare();\r
+           this.minor = (short) HttpParser.parseInt(line, ps);\r
+           return false;\r
+       } else {\r
+           this.major = 0;\r
+           this.minor = 9;\r
+           return true;\r
+       }\r
+    }\r
+\r
+    /**\r
+     * All the headers have been parsed, take any appropriate actions.\r
+     * Here we will verify that the request is HTTP/1.1 compliant\r
+     * for the Host header.\r
+     * @param parser The Mime parser.\r
+     * @exception MimeParserException if the parsing failed\r
+     * @exception IOException if an IO error occurs.\r
+     */\r
+    public void notifyEndParsing(MimeParser parser)\r
+        throws HttpParserException, IOException\r
+    {\r
+       if (major == 1 && minor == 1) {\r
+           if (getHost() == null) {\r
+               throw new HttpParserException("missing Host header", this);\r
+           }\r
+       }\r
+    }\r
+\r
+    // FIXME - I really mean FIXME\r
+\r
+    String target = null;\r
+    protected void setTarget(String target) {\r
+       this.target = target;\r
+    } \r
+\r
+    protected String getTarget() {\r
+       return target;\r
+    }\r
+\r
+    /**\r
+     * Get this request's method.\r
+     * @return The request method, as a String.\r
+     */\r
+\r
+    public String getMethod() {\r
+       return method;\r
+    }\r
+\r
+    /**\r
+     * Set this request's method.\r
+     * @param mth The request method.\r
+     */\r
+\r
+    public void setMethod(String method) {\r
+       this.method = method.intern();\r
+    }\r
+\r
+    /**\r
+     * Get this request's target URI.\r
+     * This will only return the absolute path of the requested resource, even\r
+     * if the actual request came with the full path as an URI.\r
+     * @return An URL instance, or <strong>null</strong> if undefined.\r
+     */\r
+\r
+    public URL getURL() {\r
+       return url;\r
+    }\r
+\r
+    /**\r
+     * Set this request URI.\r
+     * The provided URI should only include the absolute path of the target\r
+     * request, see the <code>setHost</code> method for how to set the actual\r
+     * host of the target resource.\r
+     * @param url The target URL of the request, as an URL instance.\r
+     */\r
+\r
+    public void setURL(URL url) {\r
+       this.url = url;\r
+    }\r
+\r
+    /**\r
+     * Get the <code>min-fresh</code> directive value of the cache control\r
+     * header.\r
+     * @return The min-fresh value, as a number of seconds, or <strong>-1\r
+     * </strong> if undefined.\r
+     */\r
+\r
+    public int getMinFresh() {\r
+       HttpCacheControl cc = getCacheControl();\r
+       return (cc == null) ? -1 : cc.getMinFresh();\r
+    }\r
+\r
+    /**\r
+     * Set the <code>min-fresh</code> directive value of the cache control\r
+     * header.\r
+     * @param minfresh The min-fresh value, in seconds, or <strong>-1</strong>\r
+     * to reset value.\r
+     */\r
+\r
+    public void setMinFresh(int minfresh) {\r
+       HttpCacheControl cc = getCacheControl();\r
+       if ( cc == null ) {\r
+           if ( minfresh == -1 ) {\r
+               return;\r
+           }\r
+           setCacheControl(cc = new HttpCacheControl(true));\r
+       }\r
+       cc.setMinFresh(minfresh);\r
+    }\r
+\r
+    /**\r
+     * Get the <code>max-stale</code> directive value of the cache control\r
+     * header.\r
+     * @return The max-stale value, as a number of seconds, or <strong>-1\r
+     * </strong> if undefined.\r
+     */\r
+\r
+    public int getMaxStale() {\r
+       HttpCacheControl cc = getCacheControl();\r
+       return (cc == null) ? -1 : cc.getMaxStale();\r
+    }\r
+\r
+    /**\r
+     * Set the <code>max-stale</code> directive value.\r
+     * @param maxstale A number of seconds giving the allowed drift for\r
+     * a resource that is no more valid, or <strong>-1</strong> to reset\r
+     * the value.\r
+     */\r
+\r
+    public void setMaxStale(int maxstale) {\r
+       HttpCacheControl cc = getCacheControl();\r
+       if ( cc == null ) {\r
+           if ( maxstale == -1 ) {\r
+               return;\r
+           }\r
+           setCacheControl(cc = new HttpCacheControl(true));\r
+       }\r
+       cc.setMaxStale(maxstale);\r
+    }\r
+\r
+    // FIXME more cache control accessors\r
+\r
+    /**\r
+     * Get this request accept list.\r
+     * @return A list of Accept clauses encoded as an array of HttpAccept\r
+     * instances, or <strong>null</strong> if undefined.\r
+     */\r
+\r
+    public HttpAccept[] getAccept() {\r
+       HeaderValue value = getHeaderValue(H_ACCEPT);\r
+       return (value != null) ? (HttpAccept[]) value.getValue() : null;\r
+    }\r
+\r
+    /**\r
+     * Set the list of accept clauses attached to this request.\r
+     * @param accepts The list of accept clauses encoded as an array\r
+     * of HttpAccept instances, or <strong>null</strong> to reset the value.\r
+     */\r
+\r
+    public void setAccept(HttpAccept accepts[]) {\r
+       setHeaderValue(H_ACCEPT\r
+                      , ((accepts == null)\r
+                         ? null\r
+                         : new HttpAcceptList(accepts)));\r
+    }\r
+\r
+    /**\r
+     * Get the list of accepted charsets for this request.\r
+     * @return The list of accepted languages encoded as an array of\r
+     * instances of HttpAcceptCharset, or <strong>null</strong> if undefined.\r
+     */\r
+\r
+    public HttpAcceptCharset[] getAcceptCharset() {\r
+       HeaderValue value = getHeaderValue(H_ACCEPT_CHARSET);\r
+       return (value != null) ? (HttpAcceptCharset[]) value.getValue():null;\r
+    }\r
+\r
+    /**\r
+     * Set the list of accepted charsets for this request.\r
+     * @param charsets The list of accepted charsets, encoded as an array\r
+     * of HttpAcceptCharset instances, or <strong>null</strong> to reset\r
+     * the value.\r
+     */\r
+\r
+    public void setAcceptCharset(HttpAcceptCharset charsets[]) {\r
+       setHeaderValue(H_ACCEPT_CHARSET\r
+                      , ((charsets == null)\r
+                         ? null\r
+                         : new HttpAcceptCharsetList(charsets)));\r
+    }\r
+\r
+    /**\r
+     * Get the list of accepted encodings.\r
+     * @return A list of token describing the accepted encodings, or <strong>\r
+     * null</strong> if undefined.\r
+     */\r
+\r
+    public HttpAcceptEncoding[] getAcceptEncoding() {\r
+       HeaderValue value = getHeaderValue(H_ACCEPT_ENCODING);\r
+       return (value != null) ? (HttpAcceptEncoding[]) value.getValue():null;\r
+    }\r
+\r
+    /**\r
+     * Set the list of accepted encodings.\r
+     * @param encodings The list of accepted encodings, as an array,\r
+     * of HttpAcceptEncoding or <strong>null</strong> to reset the value.\r
+     */\r
+\r
+    public void setAcceptEncoding(HttpAcceptEncoding encoding[]) {\r
+       setHeaderValue(H_ACCEPT_ENCODING\r
+                      , ((encoding == null)\r
+                         ? null\r
+                         : new HttpAcceptEncodingList(encoding)));\r
+    }\r
+\r
+    /**\r
+     * Get the list of accepted languages for this request.\r
+     * @return The list of accepted languages encoded as an array of\r
+     * instances of HttpAcceptLanguage, or <strong>null</strong> if\r
+     * undefined.\r
+     */\r
+\r
+    public HttpAcceptLanguage[] getAcceptLanguage() {\r
+       HeaderValue value = getHeaderValue(H_ACCEPT_LANGUAGE);\r
+       return ((value != null) \r
+               ? (HttpAcceptLanguage[]) value.getValue()\r
+               : null);\r
+    }\r
+\r
+    /**\r
+     * Set the list of accepted languages for this request.\r
+     * @param langs The list of accepted languages, encoded as an array\r
+     * of HttpAcceptLanguage instances, or <strong>null</strong> to reset\r
+     * value.\r
+     */\r
+\r
+    public void setAcceptLanguage(HttpAcceptCharset langs[]) {\r
+       setHeaderValue(H_ACCEPT_LANGUAGE\r
+                      , ((langs == null) \r
+                         ? null \r
+                         : new HttpAcceptCharsetList(langs)));\r
+    }\r
+\r
+    /**\r
+     * Get the authorization associated with this request.\r
+     * @return An instance of HttpCredential of <strong>null</strong>\r
+     * if undefined.\r
+     */\r
+\r
+    public HttpCredential getAuthorization() {\r
+       HeaderValue value = getHeaderValue(H_AUTHORIZATION);\r
+       return (value != null) ? (HttpCredential) value.getValue() : null;\r
+    }\r
+\r
+    /**\r
+     * Set the authorization associated with this request.\r
+     * @param credentials The credentials to attach to this request, or\r
+     * <strong>null</strong> to reset the value.\r
+     */\r
+\r
+    public void setAuthorization(HttpCredential credentials) {\r
+       setHeaderValue(H_AUTHORIZATION, credentials);\r
+    }\r
+\r
+    /**\r
+     * Does this request has some specific authorization infos.\r
+     * @return A boolean.\r
+     */\r
+\r
+    public boolean hasAuthorization() {\r
+       return hasHeader(H_AUTHORIZATION);\r
+    }\r
+\r
+    /**\r
+     * Get the originator (from header value) of the request.\r
+     * @return The originator description, as a String, or <strong>null\r
+     * </strong> if undefined.\r
+     */\r
+\r
+    public String getFrom() {\r
+       HeaderValue value = getHeaderValue(H_FROM);\r
+       return (value != null) ? (String) value.getValue() : null;\r
+    }\r
+\r
+    /**\r
+     * Set the originator of this request.\r
+     * @param from The description of the originator, as an email address,\r
+     * or <strong>null</strong> to reset the value.\r
+     */\r
+\r
+    public void setFrom(String from) {\r
+       setHeaderValue(H_FROM\r
+                      , ((from == null) \r
+                         ? null \r
+                         : new HttpString(true, from)));\r
+    }\r
+\r
+    /**\r
+     * Get the host header.\r
+     * @return The host header, encoded as a String, or <strong>null</strong>\r
+     * if undefined.\r
+     */\r
+\r
+    public String getHost() {\r
+       HeaderValue value = getHeaderValue(H_HOST);\r
+       return (value != null) ? (String) value.getValue() : null;\r
+    }\r
+\r
+    /**\r
+     * Set the host header value.\r
+     * @param host The String representing the target host of the request,\r
+     * or <strong>null</strong> to reset the value.\r
+     */\r
+\r
+    public void setHost(String host) {\r
+       setHeaderValue(H_HOST\r
+                      , ((host == null) ? null : new HttpString(true, host)));\r
+    }\r
+\r
+    /**\r
+     * Get the if-modified-since conditional.\r
+     * @return A long, giving the If-Modified-Since date value as the number\r
+     * of milliseconds since Java epoch, or <strong>-1</strong> if undefined.\r
+     */\r
+\r
+    public long getIfModifiedSince() {\r
+       HeaderValue value = getHeaderValue(H_IF_MODIFIED_SINCE);\r
+       return (value != null) ? ((Long) value.getValue()).longValue() : -1;\r
+    }\r
+\r
+    /**\r
+     * Set the if-modified-since conditional.\r
+     * @param ims The date of last modification, as the number of milliseconds\r
+     * since Java epoch, or <strong>-1</strong> to reset the value.\r
+     */\r
+\r
+    public void setIfModifiedSince(long ims) {\r
+       setHeaderValue(H_IF_MODIFIED_SINCE\r
+                      , ((ims == -1) ? null : new HttpDate(true, ims)));\r
+    }\r
+\r
+    /**\r
+     * Get the conditional matching set of entity tags.\r
+     * @return An array of HttpEntityTag instances, or <strong>null</strong>\r
+     * if undefined.\r
+     */\r
+\r
+    public HttpEntityTag[] getIfMatch() {\r
+       HeaderValue value = getHeaderValue(H_IF_MATCH);\r
+       return (value != null) ? (HttpEntityTag[]) value.getValue() : null;\r
+    }\r
+\r
+    /**\r
+     * Set the conditional matching set of entity tags.\r
+     * @param etags An array of HttpEntityTag, one per item in the set, or\r
+     * <strong>null</strong> to reset the header value.\r
+     */\r
+\r
+    public void setIfMatch(HttpEntityTag etags[]) {\r
+       setHeaderValue(H_IF_MATCH\r
+                      , ((etags != null)\r
+                         ? new HttpEntityTagList(etags)\r
+                         : null));\r
+    }\r
+\r
+    /**\r
+     * Get the conditional none matching entity tags.\r
+     * @return An entity tag list, encoded as an array of HttpEntityTag, or\r
+     * <strong>null</strong> if undefined.\r
+     */\r
+\r
+    public HttpEntityTag[] getIfNoneMatch() {\r
+       HeaderValue value = getHeaderValue(H_IF_NONE_MATCH);\r
+       return (value != null) ? (HttpEntityTag[]) value.getValue() : null;\r
+    }\r
+\r
+    /**\r
+     * Set the conditional none matching entity tags.\r
+     * @param etags An array of HttpEntityTag, one per item in the set,\r
+     * or <strong>null</strong> to reset the value.\r
+     */\r
+\r
+    public void setIfNoneMatch(HttpEntityTag etags[]) {\r
+       setHeaderValue(H_IF_NONE_MATCH\r
+                      , ((etags == null)\r
+                         ? null\r
+                         : new HttpEntityTagList(etags)));\r
+    }\r
+\r
+    /**\r
+     * Get the if-range conditional if any.\r
+     * Warning: This API doesn't accept <code>If-Range</code> header that\r
+     * contains date value (if you want to discuss why, send me email)\r
+     * @return An HttpEntityTag instance, or <strong>null</strong> if \r
+     * that header is not defined.\r
+     */\r
+\r
+    public HttpEntityTag getIfRange() {\r
+       HeaderValue value = getHeaderValue(H_IF_RANGE);\r
+       return ((value != null) ? (HttpEntityTag) value : null);\r
+    }\r
+\r
+    /**\r
+     * Set the if-range header value.\r
+     * @param etag The contional etag, or <strong>null</strong> to reset\r
+     * previous setting.\r
+     */\r
+\r
+    public void setIfRange(HttpEntityTag etag) {\r
+       setHeaderValue(H_IF_RANGE, etag);\r
+    }\r
+\r
+    /**\r
+     * Get the if unmodified since conditional date.\r
+     * @return The date encoded as a long number of milliseconds since\r
+     * Java runtime epoch, or <strong>-1</strong> if undefined.\r
+     */\r
+\r
+    public long getIfUnmodifiedSince() {\r
+       HeaderValue value = getHeaderValue(H_IF_UNMODIFIED_SINCE);\r
+       return (value != null) ? ((Long) value.getValue()).longValue() : -1;\r
+    }\r
+\r
+    /**\r
+     * Set the if-unmodified-since conditional date.\r
+     * @param date The date, encoded as the number of milliseconds since\r
+     * Java epoch, or <strong>-1</strong> to reset value.\r
+     */\r
+\r
+    public void setIfUnmodifiedSince(long date) {\r
+       if ( date == -1L ) {\r
+           setHeaderValue(H_IF_UNMODIFIED_SINCE, null);\r
+       } else {\r
+           setHeaderValue(H_IF_UNMODIFIED_SINCE, new HttpDate(true, date));\r
+       }\r
+    }\r
+\r
+    /**\r
+     * Get the maximum allowed count of hops for the request.\r
+     * @return An integer giving the number of hops, or <strong>-1</strong>\r
+     * if undefined.\r
+     */\r
+\r
+    public int getMaxForwards() {\r
+       HeaderValue value = getHeaderValue(H_MAX_FORWARDS);\r
+       return (value != null) ? ((Integer) value.getValue()).intValue() : -1;\r
+    }\r
+\r
+    /**\r
+     * Set the maximum allowed count of hops for that request.\r
+     * @param hops The hops count, or <strong>-1</strong> to reset value.\r
+     */\r
+\r
+    public void setMaxForwards(int hops) {\r
+       if ( hops == -1 ) {\r
+           setHeaderValue(H_MAX_FORWARDS, null);\r
+       } else {\r
+           setHeaderValue(H_MAX_FORWARDS, new HttpInteger(true, hops));\r
+       }\r
+    }\r
+\r
+    /**\r
+     * Set the proxy authorization associated with that request.\r
+     * @param credentials The credentials, or <strong>null</strong> to\r
+     * reset the value.\r
+     */\r
+\r
+    public void setProxyAuthorization(HttpCredential credentials) {\r
+       setHeaderValue(H_PROXY_AUTHORIZATION, credentials);\r
+    }\r
+\r
+    /**\r
+     * Get the authorization associated with this request.\r
+     * @return An instance of HttpCredential of <strong>null</strong>\r
+     * if undefined.\r
+     */\r
+\r
+    public HttpCredential getProxyAuthorization() {\r
+       HeaderValue value = getHeaderValue(H_PROXY_AUTHORIZATION);\r
+       return (value != null) ? (HttpCredential) value.getValue() : null;\r
+    }\r
+\r
+    /**\r
+     * Get the ranges queried by this request.\r
+     * @return A list of ranges, encoded as an array of HttpRange instance\r
+     * or <strong>null</strong> if undefined.\r
+     */\r
+\r
+    public HttpRange[] getRange() {\r
+       HeaderValue value = getHeaderValue(H_RANGE);\r
+       return (value != null) ? (HttpRange[]) value.getValue() : null;\r
+    }\r
+\r
+    /**\r
+     * Set the ranges queried by this request.\r
+     * @param ranges The list of ranges, encoded as an array of instances\r
+     * of HttpRange, or <strong>null</strong> to reset the value.\r
+     */\r
+\r
+    public void setRange(HttpRange ranges[]) {\r
+       setHeaderValue(H_RANGE\r
+                      , ((ranges == null)\r
+                         ? null\r
+                         : new HttpRangeList(ranges)));\r
+    }\r
+\r
+    /**\r
+     * Get the referer of the request.\r
+     * @return A String encoding the referer (generally an URL), or\r
+     * <strong>null</strong> if undefined.\r
+     */\r
+\r
+    public String getReferer() {\r
+       HeaderValue value = getHeaderValue(H_REFERER);\r
+       return (value != null) ? (String) value.getValue() : null;\r
+    }\r
+\r
+    /**\r
+     * Set the referer of this request.\r
+     * @param referer The referer of the request, or <strong>null</strong>\r
+     * to reset the value.\r
+     */\r
+\r
+    public void setReferer(String referer) {\r
+       setHeaderValue(H_REFERER\r
+                      , ((referer == null)\r
+                         ? null\r
+                         : new HttpString(true, referer)));\r
+    }\r
+\r
+    /**\r
+     * Get the user agent String.\r
+     * @return The user agent description, as a String, or <strong>null\r
+     * </strong> if undefined.\r
+     */\r
+\r
+    public String getUserAgent() {\r
+       HeaderValue value = getHeaderValue(H_USER_AGENT);\r
+       return (value != null) ? (String) value.getValue() : null;\r
+    }\r
+\r
+    /**\r
+     * Set the user agent description header.\r
+     * @param ua The description of the user agent emiting the request, or\r
+     * <strong>null</strong> to reset the value.\r
+     */\r
+\r
+    public void setUserAgent(String ua) {\r
+       setHeaderValue(H_USER_AGENT\r
+                      , ((ua == null) ? null : new HttpString(true, ua)));\r
+    }\r
+\r
+    /**\r
+     * Get this request's Expect header value.\r
+     * @return This header as a String.\r
+     */\r
+\r
+    public String getExpect() {\r
+       HeaderValue value = getHeaderValue(H_EXPECT);\r
+       return (value != null) ? (String) value.getValue() : null;\r
+       \r
+    }\r
+\r
+    /**\r
+     * Set this request's Expect header.\r
+     * @param exp The value of the header (ex: "100-continue".\r
+     */\r
+\r
+    public void setExpect(String expect) {\r
+       setHeaderValue(H_EXPECT\r
+                      , ((expect == null) \r
+                         ? null \r
+                         : new HttpString(true, expect)));\r
+    }\r
+\r
+    /**\r
+     * Get the list of restricted transfer encodings.\r
+     * @return A list of token describing the restreicted TE, or <strong>\r
+     * null</strong> if undefined.\r
+     */\r
+\r
+    public HttpAcceptEncoding[] getTE() {\r
+       HeaderValue value = getHeaderValue(H_TE);\r
+       return (value != null) ? (HttpAcceptEncoding[]) value.getValue():null;\r
+    }\r
+\r
+    /**\r
+     * Set the list of restricted transfer encodings\r
+     * @param encodings The list of accepted encodings, as an array,\r
+     * of HttpAcceptEncoding or <strong>null</strong> to reset the value.\r
+     */\r
+\r
+    public void setTE(HttpAcceptEncoding encoding[]) {\r
+       setHeaderValue(H_TE\r
+                      , ((encoding == null)\r
+                         ? null\r
+                         : new HttpAcceptEncodingList(encoding)));\r
+    }\r
+\r
+    /**\r
+     * Set the proxy to use for that request.\r
+     * @param proxy The proxy's URL, or <strong>null</strong> to reset value.\r
+     */\r
+\r
+    public void setProxy(URL proxy) {\r
+       this.proxy  = proxy;\r
+       this.sProxy = (proxy == null) ? null : proxy.toExternalForm();\r
+    }\r
+\r
+    /**\r
+     * Get the proxy to use for that request.\r
+     * @return The proxy's URL, or <strong>null</strong> if none is set.\r
+     */\r
+\r
+    public URL getProxy() {\r
+       return proxy;\r
+    }\r
+\r
+    /**\r
+     * Will this request use a proxy when executed ?\r
+     * @return A boolean.\r
+     */\r
+\r
+    public boolean hasProxy() {\r
+       return proxy != null;\r
+    }\r
+\r
+    public HttpRequestMessage(MimeParser parser) {\r
+       super(parser);\r
+    }\r
+\r
+    public HttpRequestMessage() {\r
+       super();\r
+    }\r
+\r
+    public static void main(String args[]) {\r
+       try {\r
+           HttpRequestMessage r = new HttpRequestMessage();\r
+           // Set general request headers:\r
+           r.setURL(new URL("http://www.w3.org/"));\r
+           r.setHost("http://www.w3.org");\r
+           r.setFrom("abaird@w3.org");\r
+           r.setReferer("http://abaird.w3.org/");\r
+           // Set the cache control directive:\r
+           HttpCacheControl c = new HttpCacheControl(true);\r
+           c.setMaxAge(10);\r
+           c.setNoStore(true);\r
+           r.setCacheControl(c);\r
+           // Emit the request:\r
+           r.emit(System.out);\r
+       } catch (Exception ex) {\r
+           ex.printStackTrace();\r
+       }\r
+    }\r
+\r
+}\r