src/share/classes/java/net/CookieManager.java

Print this page




 267         for (String headerKey : responseHeaders.keySet()) {
 268             // RFC 2965 3.2.2, key must be 'Set-Cookie2'
 269             // we also accept 'Set-Cookie' here for backward compatibility
 270             if (headerKey == null
 271                 || !(headerKey.equalsIgnoreCase("Set-Cookie2")
 272                      || headerKey.equalsIgnoreCase("Set-Cookie")
 273                     )
 274                 )
 275             {
 276                 continue;
 277             }
 278 
 279             for (String headerValue : responseHeaders.get(headerKey)) {
 280                 try {
 281                     List<HttpCookie> cookies;
 282                     try {
 283                         cookies = HttpCookie.parse(headerValue);
 284                     } catch (IllegalArgumentException e) {
 285                         // Bogus header, make an empty list and log the error
 286                         cookies = java.util.Collections.emptyList();
 287                         if (logger.isLoggable(PlatformLogger.SEVERE)) {
 288                             logger.severe("Invalid cookie for " + uri + ": " + headerValue);
 289                         }
 290                     }
 291                     for (HttpCookie cookie : cookies) {
 292                         if (cookie.getPath() == null) {
 293                             // If no path is specified, then by default
 294                             // the path is the directory of the page/doc
 295                             String path = uri.getPath();
 296                             if (!path.endsWith("/")) {
 297                                 int i = path.lastIndexOf("/");
 298                                 if (i > 0) {
 299                                     path = path.substring(0, i + 1);
 300                                 } else {
 301                                     path = "/";
 302                                 }
 303                             }
 304                             cookie.setPath(path);
 305                         }
 306 
 307                         // As per RFC 2965, section 3.3.1:




 267         for (String headerKey : responseHeaders.keySet()) {
 268             // RFC 2965 3.2.2, key must be 'Set-Cookie2'
 269             // we also accept 'Set-Cookie' here for backward compatibility
 270             if (headerKey == null
 271                 || !(headerKey.equalsIgnoreCase("Set-Cookie2")
 272                      || headerKey.equalsIgnoreCase("Set-Cookie")
 273                     )
 274                 )
 275             {
 276                 continue;
 277             }
 278 
 279             for (String headerValue : responseHeaders.get(headerKey)) {
 280                 try {
 281                     List<HttpCookie> cookies;
 282                     try {
 283                         cookies = HttpCookie.parse(headerValue);
 284                     } catch (IllegalArgumentException e) {
 285                         // Bogus header, make an empty list and log the error
 286                         cookies = java.util.Collections.emptyList();
 287                         if (logger.isLoggable(PlatformLogger.Level.SEVERE)) {
 288                             logger.severe("Invalid cookie for " + uri + ": " + headerValue);
 289                         }
 290                     }
 291                     for (HttpCookie cookie : cookies) {
 292                         if (cookie.getPath() == null) {
 293                             // If no path is specified, then by default
 294                             // the path is the directory of the page/doc
 295                             String path = uri.getPath();
 296                             if (!path.endsWith("/")) {
 297                                 int i = path.lastIndexOf("/");
 298                                 if (i > 0) {
 299                                     path = path.substring(0, i + 1);
 300                                 } else {
 301                                     path = "/";
 302                                 }
 303                             }
 304                             cookie.setPath(path);
 305                         }
 306 
 307                         // As per RFC 2965, section 3.3.1: