jdk/src/java.base/share/classes/sun/net/www/protocol/http/HttpURLConnection.java
changeset 26219 1a19360ff122
parent 25859 3317bb8137f4
child 27177 3717db2c3bfe
equal deleted inserted replaced
26218:98453f165e21 26219:1a19360ff122
     1 /*
     1 /*
     2  * Copyright (c) 1995, 2013, Oracle and/or its affiliates. All rights reserved.
     2  * Copyright (c) 1995, 2014, Oracle and/or its affiliates. All rights reserved.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     5  * This code is free software; you can redistribute it and/or modify it
     6  * under the terms of the GNU General Public License version 2 only, as
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.  Oracle designates this
     7  * published by the Free Software Foundation.  Oracle designates this
    62 import java.util.StringTokenizer;
    62 import java.util.StringTokenizer;
    63 import java.util.Iterator;
    63 import java.util.Iterator;
    64 import java.util.HashSet;
    64 import java.util.HashSet;
    65 import java.util.HashMap;
    65 import java.util.HashMap;
    66 import java.util.Set;
    66 import java.util.Set;
       
    67 import java.util.StringJoiner;
    67 import sun.net.*;
    68 import sun.net.*;
    68 import sun.net.www.*;
    69 import sun.net.www.*;
    69 import sun.net.www.http.HttpClient;
    70 import sun.net.www.http.HttpClient;
    70 import sun.net.www.http.PosterOutputStream;
    71 import sun.net.www.http.PosterOutputStream;
    71 import sun.net.www.http.ChunkedInputStream;
    72 import sun.net.www.http.ChunkedInputStream;
  1384                             !"Cookie2".equalsIgnoreCase(key)) {
  1385                             !"Cookie2".equalsIgnoreCase(key)) {
  1385                             continue;
  1386                             continue;
  1386                         }
  1387                         }
  1387                         List<String> l = entry.getValue();
  1388                         List<String> l = entry.getValue();
  1388                         if (l != null && !l.isEmpty()) {
  1389                         if (l != null && !l.isEmpty()) {
  1389                             StringBuilder cookieValue = new StringBuilder();
  1390                             StringJoiner cookieValue = new StringJoiner("; ");
  1390                             for (String value : l) {
  1391                             for (String value : l) {
  1391                                 cookieValue.append(value).append("; ");
  1392                                 cookieValue.add(value);
  1392                             }
  1393                             }
  1393                             // strip off the trailing '; '
  1394                             requests.add(key, cookieValue.toString());
  1394                             try {
       
  1395                                 requests.add(key, cookieValue.substring(0, cookieValue.length() - 2));
       
  1396                             } catch (StringIndexOutOfBoundsException ignored) {
       
  1397                                 // no-op
       
  1398                             }
       
  1399                         }
  1395                         }
  1400                     }
  1396                     }
  1401                 }
  1397                 }
  1402             }
  1398             }
  1403             if (userCookies != null) {
  1399             if (userCookies != null) {
  2868             if (cookieHandler == null || value.length() == 0)
  2864             if (cookieHandler == null || value.length() == 0)
  2869                 return value;
  2865                 return value;
  2870 
  2866 
  2871             sun.misc.JavaNetHttpCookieAccess access =
  2867             sun.misc.JavaNetHttpCookieAccess access =
  2872                     sun.misc.SharedSecrets.getJavaNetHttpCookieAccess();
  2868                     sun.misc.SharedSecrets.getJavaNetHttpCookieAccess();
  2873             StringBuilder retValue = new StringBuilder();
  2869             StringJoiner retValue = new StringJoiner(",");  // RFC 2965, comma separated
  2874             List<HttpCookie> cookies = access.parse(value);
  2870             List<HttpCookie> cookies = access.parse(value);
  2875             boolean multipleCookies = false;
       
  2876             for (HttpCookie cookie : cookies) {
  2871             for (HttpCookie cookie : cookies) {
  2877                 // skip HttpOnly cookies
  2872                 // skip HttpOnly cookies
  2878                 if (cookie.isHttpOnly())
  2873                 if (!cookie.isHttpOnly())
  2879                     continue;
  2874                     retValue.add(access.header(cookie));
  2880                 if (multipleCookies)
  2875             }
  2881                     retValue.append(',');  // RFC 2965, comma separated
  2876             return retValue.toString();
  2882                 retValue.append(access.header(cookie));
       
  2883                 multipleCookies = true;
       
  2884             }
       
  2885 
       
  2886             return retValue.length() == 0 ? "" : retValue.toString();
       
  2887         }
  2877         }
  2888 
  2878 
  2889         return value;
  2879         return value;
  2890     }
  2880     }
  2891 
  2881