jdk/src/share/classes/java/net/HttpCookie.java
changeset 1234 e3dc213d4879
parent 715 f16baef3a20e
child 1932 d3506bce7d27
equal deleted inserted replaced
1153:6b88c071a015 1234:e3dc213d4879
    73     private String domain;      // Domain=VALUE ... domain that sees cookie
    73     private String domain;      // Domain=VALUE ... domain that sees cookie
    74     private long maxAge = MAX_AGE_UNSPECIFIED;  // Max-Age=VALUE ... cookies auto-expire
    74     private long maxAge = MAX_AGE_UNSPECIFIED;  // Max-Age=VALUE ... cookies auto-expire
    75     private String path;        // Path=VALUE ... URLs that see the cookie
    75     private String path;        // Path=VALUE ... URLs that see the cookie
    76     private String portlist;    // Port[="portlist"] ... the port cookie may be returned to
    76     private String portlist;    // Port[="portlist"] ... the port cookie may be returned to
    77     private boolean secure;     // Secure ... e.g. use SSL
    77     private boolean secure;     // Secure ... e.g. use SSL
       
    78     private boolean httpOnly;   // HttpOnly ... i.e. not accessible to scripts
    78     private int version = 1;    // Version=1 ... RFC 2965 style
    79     private int version = 1;    // Version=1 ... RFC 2965 style
    79 
    80 
    80     //
    81     //
    81     // Hold the creation time (in seconds) of the http cookie for later
    82     // Hold the creation time (in seconds) of the http cookie for later
    82     // expiration calculation
    83     // expiration calculation
   654         }
   655         }
   655 
   656 
   656         version = v;
   657         version = v;
   657     }
   658     }
   658 
   659 
       
   660     /**
       
   661      * Returns {@code true} if this cookie contains the <i>HttpOnly</i>
       
   662      * attribute. This means that the cookie should not be accessible to
       
   663      * scripting engines, like javascript.
       
   664      *
       
   665      * @return {@code true} if this cookie should be considered http only.
       
   666      * @see #setHttpOnly(boolean)
       
   667      */
       
   668     public boolean isHttpOnly()
       
   669     {
       
   670         return httpOnly;
       
   671     }
       
   672 
       
   673     /**
       
   674      * Indicates whether the cookie should be considered HTTP Only. If set to
       
   675      * {@code true} it means the cookie should not be accessible to scripting
       
   676      * engines like javascript.
       
   677      *
       
   678      * @param httpOnly if {@code true} make the cookie HTTP only, i.e.
       
   679      *                 only visible as part of an HTTP request.
       
   680      * @see #isHttpOnly()
       
   681      */
       
   682     public void setHttpOnly(boolean httpOnly)
       
   683     {
       
   684         this.httpOnly = httpOnly;
       
   685     }
   659 
   686 
   660     /**
   687     /**
   661      * The utility method to check whether a host name is in a domain
   688      * The utility method to check whether a host name is in a domain
   662      * or not.
   689      * or not.
   663      *
   690      *
   875             || name.equalsIgnoreCase("Max-Age")
   902             || name.equalsIgnoreCase("Max-Age")
   876             || name.equalsIgnoreCase("Path")
   903             || name.equalsIgnoreCase("Path")
   877             || name.equalsIgnoreCase("Port")            // rfc2965 only
   904             || name.equalsIgnoreCase("Port")            // rfc2965 only
   878             || name.equalsIgnoreCase("Secure")
   905             || name.equalsIgnoreCase("Secure")
   879             || name.equalsIgnoreCase("Version")
   906             || name.equalsIgnoreCase("Version")
       
   907             || name.equalsIgnoreCase("HttpOnly")
   880             || name.charAt(0) == '$')
   908             || name.charAt(0) == '$')
   881         {
   909         {
   882             return true;
   910             return true;
   883         }
   911         }
   884 
   912 
   994         assignors.put("secure", new CookieAttributeAssignor(){
  1022         assignors.put("secure", new CookieAttributeAssignor(){
   995                 public void assign(HttpCookie cookie, String attrName, String attrValue) {
  1023                 public void assign(HttpCookie cookie, String attrName, String attrValue) {
   996                     cookie.setSecure(true);
  1024                     cookie.setSecure(true);
   997                 }
  1025                 }
   998             });
  1026             });
       
  1027         assignors.put("httponly", new CookieAttributeAssignor(){
       
  1028                 public void assign(HttpCookie cookie, String attrName, String attrValue) {
       
  1029                     cookie.setHttpOnly(true);
       
  1030                 }
       
  1031             });
   999         assignors.put("version", new CookieAttributeAssignor(){
  1032         assignors.put("version", new CookieAttributeAssignor(){
  1000                 public void assign(HttpCookie cookie, String attrName, String attrValue) {
  1033                 public void assign(HttpCookie cookie, String attrName, String attrValue) {
  1001                     try {
  1034                     try {
  1002                         int version = Integer.parseInt(attrValue);
  1035                         int version = Integer.parseInt(attrValue);
  1003                         cookie.setVersion(version);
  1036                         cookie.setVersion(version);