test/jdk/java/net/httpclient/CookieHeaderTest.java
author dfuchs
Thu, 29 Mar 2018 15:32:18 +0100
branchhttp-client-branch
changeset 56367 875d85699981
parent 56366 d50e3549506e
child 56451 9585061fdb04
permissions -rw-r--r--
http-client-branch: fix small mistake in CookieHeaderTest.java
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
56366
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
     1
/*
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
     2
 * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
     4
 *
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
     7
 * published by the Free Software Foundation.
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
     8
 *
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
    13
 * accompanied this code).
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
    14
 *
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
    18
 *
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
    21
 * questions.
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
    22
 */
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
    23
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
    24
/*
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
    25
 * @test
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
    26
 * @bug 8199851
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
    27
 * @summary Test for multiple vs single cookie header for HTTP/2 vs HTTP/1.1
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
    28
 * @modules java.base/sun.net.www.http
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
    29
 *          java.net.http/jdk.internal.net.http.common
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
    30
 *          java.net.http/jdk.internal.net.http.frame
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
    31
 *          java.net.http/jdk.internal.net.http.hpack
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
    32
 *          java.logging
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
    33
 *          jdk.httpserver
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
    34
 * @library /lib/testlibrary /test/lib http2/server
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
    35
 * @build Http2TestServer
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
    36
 * @build jdk.testlibrary.SimpleSSLContext
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
    37
 * @run testng/othervm
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
    38
 *       -Djdk.httpclient.HttpClient.log=trace,headers,requests
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
    39
 *       CookieHeaderTest
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
    40
 */
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
    41
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
    42
import com.sun.net.httpserver.HttpServer;
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
    43
import com.sun.net.httpserver.HttpsConfigurator;
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
    44
import com.sun.net.httpserver.HttpsServer;
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
    45
import jdk.testlibrary.SimpleSSLContext;
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
    46
import org.testng.annotations.AfterTest;
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
    47
import org.testng.annotations.BeforeTest;
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
    48
import org.testng.annotations.DataProvider;
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
    49
import org.testng.annotations.Test;
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
    50
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
    51
import javax.net.ServerSocketFactory;
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
    52
import javax.net.ssl.SSLContext;
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
    53
import java.io.IOException;
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
    54
import java.io.InputStream;
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
    55
import java.io.OutputStream;
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
    56
import java.io.OutputStreamWriter;
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
    57
import java.io.PrintWriter;
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
    58
import java.io.Writer;
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
    59
import java.net.CookieHandler;
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
    60
import java.net.CookieManager;
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
    61
import java.net.InetAddress;
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
    62
import java.net.InetSocketAddress;
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
    63
import java.net.ServerSocket;
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
    64
import java.net.Socket;
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
    65
import java.net.URI;
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
    66
import java.net.http.HttpClient;
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
    67
import java.net.http.HttpClient.Redirect;
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
    68
import java.net.http.HttpRequest;
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
    69
import java.net.http.HttpResponse;
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
    70
import java.net.http.HttpResponse.BodyHandlers;
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
    71
import java.util.ArrayList;
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
    72
import java.util.Arrays;
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
    73
import java.util.Collections;
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
    74
import java.util.HashMap;
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
    75
import java.util.List;
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
    76
import java.util.Locale;
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
    77
import java.util.Map;
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
    78
import java.util.StringTokenizer;
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
    79
import java.util.concurrent.ConcurrentHashMap;
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
    80
import java.util.concurrent.ConcurrentLinkedQueue;
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
    81
import java.util.concurrent.atomic.AtomicLong;
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
    82
import java.util.stream.Collectors;
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
    83
import java.util.stream.Stream;
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
    84
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
    85
import static java.lang.System.out;
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
    86
import static java.nio.charset.StandardCharsets.UTF_8;
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
    87
import static org.testng.Assert.assertEquals;
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
    88
import static org.testng.Assert.assertTrue;
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
    89
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
    90
public class CookieHeaderTest implements HttpServerAdapters {
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
    91
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
    92
    SSLContext sslContext;
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
    93
    HttpTestServer httpTestServer;        // HTTP/1.1    [ 6 servers ]
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
    94
    HttpTestServer httpsTestServer;       // HTTPS/1.1
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
    95
    HttpTestServer http2TestServer;       // HTTP/2 ( h2c )
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
    96
    HttpTestServer https2TestServer;      // HTTP/2 ( h2  )
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
    97
    DummyServer httpDummyServer;
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
    98
    DummyServer httpsDummyServer;
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
    99
    String httpURI;
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   100
    String httpsURI;
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   101
    String http2URI;
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   102
    String https2URI;
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   103
    String httpDummy;
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   104
    String httpsDummy;
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   105
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   106
    static final String MESSAGE = "Basic CookieHeaderTest message body";
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   107
    static final int ITERATIONS = 3;
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   108
    static final long start = System.nanoTime();
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   109
    public static String now() {
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   110
        long now = System.nanoTime() - start;
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   111
        long secs = now / 1000_000_000;
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   112
        long mill = (now % 1000_000_000) / 1000_000;
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   113
        long nan = now % 1000_000;
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   114
        return String.format("[%d s, %d ms, %d ns] ", secs, mill, nan);
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   115
    }
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   116
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   117
    @DataProvider(name = "positive")
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   118
    public Object[][] positive() {
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   119
        return new Object[][] {
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   120
                { httpURI, HttpClient.Version.HTTP_1_1  },
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   121
                { httpsURI, HttpClient.Version.HTTP_1_1  },
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   122
                { httpDummy, HttpClient.Version.HTTP_1_1 },
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   123
                { httpsDummy, HttpClient.Version.HTTP_1_1 },
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   124
                { httpURI, HttpClient.Version.HTTP_2  },
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   125
                { httpsURI, HttpClient.Version.HTTP_2  },
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   126
                { httpDummy, HttpClient.Version.HTTP_2 },
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   127
                { httpsDummy, HttpClient.Version.HTTP_2 },
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   128
                { http2URI, null  },
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   129
                { https2URI, null },
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   130
        };
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   131
    }
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   132
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   133
    static final AtomicLong requestCounter = new AtomicLong();
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   134
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   135
    @Test(dataProvider = "positive")
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   136
    void test(String uriString, HttpClient.Version version) throws Exception {
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   137
        out.printf("%n---- starting (%s) ----%n", uriString);
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   138
        ConcurrentHashMap<String, List<String>> cookieHeaders
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   139
                = new ConcurrentHashMap<>();
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   140
        CookieHandler cookieManager = new TestCookieHandler(cookieHeaders);
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   141
        HttpClient client = HttpClient.newBuilder()
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   142
                .followRedirects(Redirect.ALWAYS)
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   143
                .cookieHandler(cookieManager)
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   144
                .sslContext(sslContext)
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   145
                .build();
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   146
        assert client.cookieHandler().isPresent();
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   147
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   148
        URI uri = URI.create(uriString);
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   149
        List<String> cookies = new ArrayList<>();
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   150
        cookies.add("CUSTOMER=ARTHUR_DENT");
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   151
        cookies.add("LOCATION=TR\u0100IN_STATION");
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   152
        cookies.add("LOC\u0100TION=TRAIN_STATION");
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   153
        cookies.add("ORDER=BISCUITS");
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   154
        cookieHeaders.put("Cookie", cookies);
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   155
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   156
        HttpRequest.Builder requestBuilder = HttpRequest.newBuilder(uri)
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   157
                .header("X-uuid", "uuid-" + requestCounter.incrementAndGet());
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   158
        if (version != null) {
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   159
            requestBuilder.version(version);
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   160
        }
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   161
        HttpRequest request = requestBuilder.build();
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   162
        out.println("Initial request: " + request.uri());
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   163
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   164
        for (int i=0; i< ITERATIONS; i++) {
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   165
            out.println("iteration: " + i);
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   166
            HttpResponse<String> response = client.send(request, BodyHandlers.ofString());
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   167
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   168
            out.println("  Got response: " + response);
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   169
            out.println("  Got body Path: " + response.body());
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   170
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   171
            assertEquals(response.statusCode(), 200);
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   172
            assertEquals(response.body(), MESSAGE);
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   173
            assertEquals(response.headers().allValues("X-Request-Cookie"),
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   174
                    cookies.stream()
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   175
                            .filter(s -> !s.startsWith("LOC"))
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   176
                            .collect(Collectors.toList()));
56367
875d85699981 http-client-branch: fix small mistake in CookieHeaderTest.java
dfuchs
parents: 56366
diff changeset
   177
            requestBuilder = HttpRequest.newBuilder(uri)
875d85699981 http-client-branch: fix small mistake in CookieHeaderTest.java
dfuchs
parents: 56366
diff changeset
   178
                    .header("X-uuid", "uuid-" + requestCounter.incrementAndGet());
875d85699981 http-client-branch: fix small mistake in CookieHeaderTest.java
dfuchs
parents: 56366
diff changeset
   179
            if (version != null) {
875d85699981 http-client-branch: fix small mistake in CookieHeaderTest.java
dfuchs
parents: 56366
diff changeset
   180
                requestBuilder.version(version);
875d85699981 http-client-branch: fix small mistake in CookieHeaderTest.java
dfuchs
parents: 56366
diff changeset
   181
            }
875d85699981 http-client-branch: fix small mistake in CookieHeaderTest.java
dfuchs
parents: 56366
diff changeset
   182
            request = requestBuilder.build();
56366
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   183
        }
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   184
    }
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   185
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   186
    // -- Infrastructure
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   187
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   188
    @BeforeTest
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   189
    public void setup() throws Exception {
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   190
        sslContext = new SimpleSSLContext().get();
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   191
        if (sslContext == null)
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   192
            throw new AssertionError("Unexpected null sslContext");
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   193
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   194
        InetSocketAddress sa = new InetSocketAddress(InetAddress.getLoopbackAddress(), 0);
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   195
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   196
        httpTestServer = HttpTestServer.of(HttpServer.create(sa, 0));
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   197
        httpTestServer.addHandler(new CookieValidationHandler(), "/http1/cookie/");
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   198
        httpURI = "http://" + httpTestServer.serverAuthority() + "/http1/cookie/retry";
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   199
        HttpsServer httpsServer = HttpsServer.create(sa, 0);
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   200
        httpsServer.setHttpsConfigurator(new HttpsConfigurator(sslContext));
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   201
        httpsTestServer = HttpTestServer.of(httpsServer);
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   202
        httpsTestServer.addHandler(new CookieValidationHandler(),"/https1/cookie/");
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   203
        httpsURI = "https://" + httpsTestServer.serverAuthority() + "/https1/cookie/retry";
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   204
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   205
        http2TestServer = HttpTestServer.of(new Http2TestServer("localhost", false, 0));
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   206
        http2TestServer.addHandler(new CookieValidationHandler(), "/http2/cookie/");
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   207
        http2URI = "http://" + http2TestServer.serverAuthority() + "/http2/cookie/retry";
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   208
        https2TestServer = HttpTestServer.of(new Http2TestServer("localhost", true, 0));
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   209
        https2TestServer.addHandler(new CookieValidationHandler(), "/https2/cookie/");
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   210
        https2URI = "https://" + https2TestServer.serverAuthority() + "/https2/cookie/retry";
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   211
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   212
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   213
        // DummyServer
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   214
        httpDummyServer = DummyServer.create(sa);
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   215
        httpsDummyServer = DummyServer.create(sa, sslContext);
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   216
        httpDummy = "http://" + httpDummyServer.serverAuthority() + "/http1/dummy/x";
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   217
        httpsDummy = "https://" + httpsDummyServer.serverAuthority() + "/https1/dummy/x";
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   218
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   219
        httpTestServer.start();
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   220
        httpsTestServer.start();
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   221
        http2TestServer.start();
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   222
        https2TestServer.start();
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   223
        httpDummyServer.start();
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   224
        httpsDummyServer.start();
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   225
    }
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   226
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   227
    @AfterTest
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   228
    public void teardown() throws Exception {
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   229
        httpTestServer.stop();
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   230
        httpsTestServer.stop();
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   231
        http2TestServer.stop();
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   232
        https2TestServer.stop();
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   233
        httpsDummyServer.stopServer();
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   234
        httpsDummyServer.stopServer();
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   235
    }
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   236
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   237
    static class TestCookieHandler extends CookieHandler {
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   238
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   239
        final ConcurrentHashMap<String, List<String>> cookies;
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   240
        TestCookieHandler(ConcurrentHashMap<String, List<String>> map) {
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   241
            this.cookies = map;
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   242
        }
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   243
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   244
        @Override
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   245
        public Map<String, List<String>> get(URI uri, Map<String, List<String>> requestHeaders)
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   246
                throws IOException
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   247
        {
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   248
            return cookies;
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   249
        }
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   250
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   251
        @Override
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   252
        public void put(URI uri, Map<String, List<String>> responseHeaders)
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   253
                throws IOException
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   254
        {
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   255
            // do nothing
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   256
        }
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   257
    }
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   258
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   259
    static class CookieValidationHandler implements HttpTestHandler {
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   260
        ConcurrentHashMap<String,String> closedRequests = new ConcurrentHashMap<>();
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   261
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   262
        @Override
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   263
        public void handle(HttpTestExchange t) throws IOException {
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   264
            System.out.println("CookieValidationHandler for: " + t.getRequestURI());
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   265
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   266
            List<String> uuids = t.getRequestHeaders().get("X-uuid");
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   267
            if (uuids == null || uuids.size() != 1) {
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   268
                readAllRequestData(t);
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   269
                try (OutputStream os = t.getResponseBody()) {
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   270
                    String msg = "Incorrect uuid header values:[" + uuids + "]";
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   271
                    (new RuntimeException(msg)).printStackTrace();
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   272
                    t.sendResponseHeaders(500, -1);
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   273
                    os.write(msg.getBytes(UTF_8));
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   274
                }
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   275
                return;
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   276
            }
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   277
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   278
            String uuid = uuids.get(0);
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   279
            // retrying
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   280
            if (closedRequests.putIfAbsent(uuid, t.getRequestURI().toString()) == null) {
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   281
                if (t.getExchangeVersion() == HttpClient.Version.HTTP_1_1) {
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   282
                    // Throwing an exception here only causes a retry
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   283
                    // with HTTP_1_1 - where it forces the server to close
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   284
                    // the connection.
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   285
                    // For HTTP/2 then throwing an IOE would cause the server
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   286
                    // to close the stream, and throwing anything else would
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   287
                    // cause it to close the connection, but neither would
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   288
                    // cause the client to retry.
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   289
                    // So we simply do not try to retry with HTTP/2 and just verify
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   290
                    // we have received the expected cookie
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   291
                    throw new IOException("Closing on first request");
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   292
                }
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   293
            }
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   294
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   295
            // Check whether this request was upgraded.
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   296
            // An upgraded request will have a version of HTTP_2 and
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   297
            // an Upgrade: h2c header
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   298
            HttpClient.Version version = t.getExchangeVersion();
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   299
            List<String> upgrade = t.getRequestHeaders().get("Upgrade");
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   300
            if (upgrade == null) upgrade = List.of();
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   301
            boolean upgraded = version == HttpClient.Version.HTTP_2
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   302
                    && upgrade.stream().anyMatch("h2c"::equalsIgnoreCase);
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   303
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   304
            // not retrying
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   305
            readAllRequestData(t);
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   306
            try (OutputStream os = t.getResponseBody()) {
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   307
                List<String> cookie = t.getRequestHeaders().get("Cookie");
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   308
                if (cookie != null) {
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   309
                    if (version == HttpClient.Version.HTTP_1_1 || upgraded) {
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   310
                        if (cookie.size() == 1) {
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   311
                            cookie = List.of(cookie.get(0).split("; "));
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   312
                        } else if (cookie.size() > 1) {
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   313
                            String msg = "Found multiple 'Cookie:' lines for version=%s (upgraded=%s): %s";
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   314
                            msg = String.format(msg, version, upgraded, cookie);
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   315
                            (new RuntimeException(msg)).printStackTrace();
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   316
                            t.sendResponseHeaders(500, -1);
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   317
                            os.write(msg.getBytes(UTF_8));
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   318
                            return;
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   319
                        }
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   320
                    }
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   321
                    Collections.sort(cookie = new ArrayList<String>(cookie));
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   322
                }
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   323
                if (cookie == null || cookie.size() == 0) {
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   324
                    String msg = "No cookie header present";
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   325
                    (new RuntimeException(msg)).printStackTrace();
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   326
                    t.sendResponseHeaders(500, -1);
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   327
                    os.write(msg.getBytes(UTF_8));
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   328
                } else if (!cookie.get(0).equals("CUSTOMER=ARTHUR_DENT")) {
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   329
                    String msg = "Incorrect cookie header value:[" + cookie.get(0) + "]";
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   330
                    (new RuntimeException(msg)).printStackTrace();
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   331
                    t.sendResponseHeaders(500, -1);
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   332
                    os.write(msg.getBytes(UTF_8));
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   333
                } else if (cookie.size() == 2 && !cookie.get(1).equals("ORDER=BISCUITS")) {
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   334
                    String msg = "Incorrect cookie header value:[" + cookie.get(0) + "]";
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   335
                    (new RuntimeException(msg)).printStackTrace();
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   336
                    t.sendResponseHeaders(500, -1);
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   337
                    os.write(msg.getBytes(UTF_8));
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   338
                } else if (cookie.size() != 2) {
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   339
                    String msg = "Incorrect cookie header values:[" + cookie + "]";
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   340
                    (new RuntimeException(msg)).printStackTrace();
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   341
                    t.sendResponseHeaders(500, -1);
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   342
                    os.write(msg.getBytes(UTF_8));
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   343
                } else {
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   344
                    assert cookie.get(0).equals("CUSTOMER=ARTHUR_DENT");
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   345
                    byte[] bytes = MESSAGE.getBytes(UTF_8);
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   346
                    for (String value : cookie) {
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   347
                        t.getResponseHeaders().addHeader("X-Request-Cookie", value);
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   348
                    }
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   349
                    t.sendResponseHeaders(200, bytes.length);
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   350
                    os.write(bytes);
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   351
                }
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   352
            } finally {
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   353
                closedRequests.remove(uuid);
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   354
            }
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   355
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   356
        }
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   357
    }
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   358
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   359
    static void readAllRequestData(HttpTestExchange t) throws IOException {
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   360
        try (InputStream is = t.getRequestBody()) {
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   361
            is.readAllBytes();
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   362
        }
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   363
    }
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   364
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   365
    static class DummyServer extends Thread {
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   366
        final ServerSocket ss;
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   367
        final boolean secure;
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   368
        ConcurrentLinkedQueue<Socket> connections = new ConcurrentLinkedQueue<>();
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   369
        volatile boolean stopped;
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   370
        DummyServer(ServerSocket ss, boolean secure) {
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   371
            super("DummyServer[" + ss.getLocalPort()+"]");
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   372
            this.secure = secure;
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   373
            this.ss = ss;
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   374
        }
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   375
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   376
        // This is a bit shaky. It doesn't handle continuation
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   377
        // lines, but our client shouldn't send any.
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   378
        // Read a line from the input stream, swallowing the final
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   379
        // \r\n sequence. Stops at the first \n, doesn't complain
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   380
        // if it wasn't preceded by '\r'.
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   381
        //
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   382
        String readLine(InputStream r) throws IOException {
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   383
            StringBuilder b = new StringBuilder();
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   384
            int c;
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   385
            while ((c = r.read()) != -1) {
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   386
                if (c == '\n') break;
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   387
                b.appendCodePoint(c);
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   388
            }
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   389
            if (b.codePointAt(b.length() -1) == '\r') {
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   390
                b.delete(b.length() -1, b.length());
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   391
            }
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   392
            return b.toString();
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   393
        }
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   394
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   395
        @Override
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   396
        public void run() {
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   397
            try {
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   398
                while(!stopped) {
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   399
                    Socket clientConnection = ss.accept();
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   400
                    connections.add(clientConnection);
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   401
                    System.out.println(now() + getName() + ": Client accepted");
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   402
                    StringBuilder headers = new StringBuilder();
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   403
                    Socket targetConnection = null;
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   404
                    InputStream  ccis = clientConnection.getInputStream();
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   405
                    OutputStream ccos = clientConnection.getOutputStream();
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   406
                    Writer w = new OutputStreamWriter(
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   407
                            clientConnection.getOutputStream(), "UTF-8");
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   408
                    PrintWriter pw = new PrintWriter(w);
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   409
                    System.out.println(now() + getName() + ": Reading request line");
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   410
                    String requestLine = readLine(ccis);
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   411
                    System.out.println(now() + getName() + ": Request line: " + requestLine);
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   412
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   413
                    StringTokenizer tokenizer = new StringTokenizer(requestLine);
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   414
                    String method = tokenizer.nextToken();
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   415
                    assert method.equalsIgnoreCase("POST") || method.equalsIgnoreCase("GET");
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   416
                    String path = tokenizer.nextToken();
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   417
                    URI uri;
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   418
                    try {
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   419
                        String hostport = serverAuthority();
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   420
                        uri = new URI((secure ? "https" : "http") +"://" + hostport + path);
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   421
                    } catch (Throwable x) {
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   422
                        System.err.printf("Bad target address: \"%s\" in \"%s\"%n",
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   423
                                path, requestLine);
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   424
                        clientConnection.close();
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   425
                        continue;
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   426
                    }
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   427
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   428
                    // Read all headers until we find the empty line that
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   429
                    // signals the end of all headers.
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   430
                    String line = requestLine;
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   431
                    String cookies = null;
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   432
                    while (!line.equals("")) {
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   433
                        System.out.println(now() + getName() + ": Reading header: "
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   434
                                + (line = readLine(ccis)));
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   435
                        if (line.startsWith("Cookie:")) {
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   436
                            if (cookies == null) cookies = line;
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   437
                            else cookies = cookies + "\n" + line;
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   438
                        }
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   439
                        headers.append(line).append("\r\n");
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   440
                    }
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   441
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   442
                    StringBuilder response = new StringBuilder();
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   443
                    StringBuilder xheaders = new StringBuilder();
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   444
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   445
                    int index = headers.toString()
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   446
                            .toLowerCase(Locale.US)
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   447
                            .indexOf("content-length: ");
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   448
                    if (index >= 0) {
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   449
                        index = index + "content-length: ".length();
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   450
                        String cl = headers.toString().substring(index);
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   451
                        StringTokenizer tk = new StringTokenizer(cl);
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   452
                        int len = Integer.parseInt(tk.nextToken());
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   453
                        System.out.println(now() + getName()
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   454
                                + ": received body: "
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   455
                                + new String(ccis.readNBytes(len), UTF_8));
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   456
                    }
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   457
                    String resp = MESSAGE;
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   458
                    String status = "200 OK";
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   459
                    if (cookies == null) {
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   460
                        resp = "No cookies found in headers";
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   461
                        status = "500 Internal Server Error";
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   462
                    } else if (cookies.contains("\n")) {
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   463
                        resp = "More than one 'Cookie:' line found: "
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   464
                                + Arrays.asList(cookies.split("\n"));
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   465
                        status = "500 Internal Server Error";
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   466
                    } else {
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   467
                        List<String> values =
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   468
                                Stream.of(cookies.substring("Cookie:".length()).trim().split("; "))
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   469
                                        .map(String::trim)
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   470
                                        .collect(Collectors.toList());
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   471
                        Collections.sort(values);
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   472
                        if (values.size() != 2) {
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   473
                            resp = "Bad cookie list: " + values;
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   474
                            status = "500 Internal Server Error";
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   475
                        } else if (!values.get(0).equals("CUSTOMER=ARTHUR_DENT")) {
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   476
                            resp = "Unexpected cookie: " + values.get(0) + " in " + values;
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   477
                            status = "500 Internal Server Error";
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   478
                        } else if (!values.get(1).equals("ORDER=BISCUITS")) {
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   479
                            resp = "Unexpected cookie: " + values.get(1) + " in " + values;
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   480
                            status = "500 Internal Server Error";
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   481
                        } else {
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   482
                            for (String cookie : values) {
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   483
                                xheaders.append("X-Request-Cookie: ")
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   484
                                        .append(cookie)
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   485
                                        .append("\r\n");
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   486
                            }
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   487
                        }
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   488
                    }
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   489
                    byte[] b = resp.getBytes(UTF_8);
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   490
                    System.out.println(now()
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   491
                            + getName() + ": sending back " + uri);
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   492
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   493
                    response.append("HTTP/1.1 ")
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   494
                            .append(status)
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   495
                            .append("\r\nContent-Length: ")
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   496
                            .append(b.length)
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   497
                            .append("\r\n")
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   498
                            .append(xheaders)
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   499
                            .append("\r\n");
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   500
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   501
                    // Then send the 200 OK response to the client
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   502
                    System.out.println(now() + getName() + ": Sending "
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   503
                            + response);
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   504
                    pw.print(response);
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   505
                    pw.flush();
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   506
                    ccos.write(b);
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   507
                    ccos.flush();
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   508
                    ccos.close();
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   509
                    connections.remove(clientConnection);
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   510
                    clientConnection.close();
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   511
                }
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   512
            } catch (Throwable t) {
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   513
                if (!stopped) {
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   514
                    System.out.println(now() + getName() + ": failed: " + t);
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   515
                    t.printStackTrace();
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   516
                    try {
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   517
                        stopServer();
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   518
                    } catch (Throwable e) {
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   519
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   520
                    }
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   521
                }
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   522
            } finally {
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   523
                System.out.println(now() + getName() + ": exiting");
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   524
            }
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   525
        }
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   526
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   527
        void close(Socket s) {
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   528
            try {
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   529
                s.close();
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   530
            } catch(Throwable t) {
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   531
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   532
            }
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   533
        }
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   534
        public void stopServer() throws IOException {
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   535
            stopped = true;
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   536
            ss.close();
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   537
            connections.forEach(this::close);
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   538
        }
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   539
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   540
        public String serverAuthority() {
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   541
            return InetAddress.getLoopbackAddress().getHostName() + ":"
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   542
                    + ss.getLocalPort();
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   543
        }
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   544
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   545
        static DummyServer create(InetSocketAddress sa) throws IOException {
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   546
            ServerSocket ss = ServerSocketFactory.getDefault()
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   547
                    .createServerSocket(sa.getPort(), -1, sa.getAddress());
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   548
            return  new DummyServer(ss, false);
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   549
        }
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   550
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   551
        static DummyServer create(InetSocketAddress sa, SSLContext sslContext) throws IOException {
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   552
            ServerSocket ss = sslContext.getServerSocketFactory()
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   553
                    .createServerSocket(sa.getPort(), -1, sa.getAddress());
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   554
            return new DummyServer(ss, true);
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   555
        }
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   556
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   557
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   558
    }
d50e3549506e http-client-branch: HTTP/1.1 requests should use a single 'Cookie' header for cookies
dfuchs
parents:
diff changeset
   559
}