jdk/test/java/net/HttpCookie/IllegalCookieNameTest.java
author juh
Tue, 25 Jun 2013 14:41:46 -0700
changeset 18552 005e115dc6ee
parent 13259 f8aa59b3988e
child 38883 d5de564f8089
permissions -rw-r--r--
8017326: Cleanup of the javadoc <code> tag in java.security.spec Summary: Convert javadoc <code> and <tt> tags to {@code ...} Reviewed-by: darcy
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
13259
f8aa59b3988e 7183292: HttpURLConnection.getHeaderFields() throws IllegalArgumentException: Illegal cookie name
michaelm
parents:
diff changeset
     1
/*
f8aa59b3988e 7183292: HttpURLConnection.getHeaderFields() throws IllegalArgumentException: Illegal cookie name
michaelm
parents:
diff changeset
     2
 * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
f8aa59b3988e 7183292: HttpURLConnection.getHeaderFields() throws IllegalArgumentException: Illegal cookie name
michaelm
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
f8aa59b3988e 7183292: HttpURLConnection.getHeaderFields() throws IllegalArgumentException: Illegal cookie name
michaelm
parents:
diff changeset
     4
 *
f8aa59b3988e 7183292: HttpURLConnection.getHeaderFields() throws IllegalArgumentException: Illegal cookie name
michaelm
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
f8aa59b3988e 7183292: HttpURLConnection.getHeaderFields() throws IllegalArgumentException: Illegal cookie name
michaelm
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
f8aa59b3988e 7183292: HttpURLConnection.getHeaderFields() throws IllegalArgumentException: Illegal cookie name
michaelm
parents:
diff changeset
     7
 * published by the Free Software Foundation.
f8aa59b3988e 7183292: HttpURLConnection.getHeaderFields() throws IllegalArgumentException: Illegal cookie name
michaelm
parents:
diff changeset
     8
 *
f8aa59b3988e 7183292: HttpURLConnection.getHeaderFields() throws IllegalArgumentException: Illegal cookie name
michaelm
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
f8aa59b3988e 7183292: HttpURLConnection.getHeaderFields() throws IllegalArgumentException: Illegal cookie name
michaelm
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
f8aa59b3988e 7183292: HttpURLConnection.getHeaderFields() throws IllegalArgumentException: Illegal cookie name
michaelm
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
f8aa59b3988e 7183292: HttpURLConnection.getHeaderFields() throws IllegalArgumentException: Illegal cookie name
michaelm
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
f8aa59b3988e 7183292: HttpURLConnection.getHeaderFields() throws IllegalArgumentException: Illegal cookie name
michaelm
parents:
diff changeset
    13
 * accompanied this code).
f8aa59b3988e 7183292: HttpURLConnection.getHeaderFields() throws IllegalArgumentException: Illegal cookie name
michaelm
parents:
diff changeset
    14
 *
f8aa59b3988e 7183292: HttpURLConnection.getHeaderFields() throws IllegalArgumentException: Illegal cookie name
michaelm
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
f8aa59b3988e 7183292: HttpURLConnection.getHeaderFields() throws IllegalArgumentException: Illegal cookie name
michaelm
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
f8aa59b3988e 7183292: HttpURLConnection.getHeaderFields() throws IllegalArgumentException: Illegal cookie name
michaelm
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
f8aa59b3988e 7183292: HttpURLConnection.getHeaderFields() throws IllegalArgumentException: Illegal cookie name
michaelm
parents:
diff changeset
    18
 *
f8aa59b3988e 7183292: HttpURLConnection.getHeaderFields() throws IllegalArgumentException: Illegal cookie name
michaelm
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
f8aa59b3988e 7183292: HttpURLConnection.getHeaderFields() throws IllegalArgumentException: Illegal cookie name
michaelm
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
f8aa59b3988e 7183292: HttpURLConnection.getHeaderFields() throws IllegalArgumentException: Illegal cookie name
michaelm
parents:
diff changeset
    21
 * questions.
f8aa59b3988e 7183292: HttpURLConnection.getHeaderFields() throws IllegalArgumentException: Illegal cookie name
michaelm
parents:
diff changeset
    22
 */
f8aa59b3988e 7183292: HttpURLConnection.getHeaderFields() throws IllegalArgumentException: Illegal cookie name
michaelm
parents:
diff changeset
    23
f8aa59b3988e 7183292: HttpURLConnection.getHeaderFields() throws IllegalArgumentException: Illegal cookie name
michaelm
parents:
diff changeset
    24
/* @test
f8aa59b3988e 7183292: HttpURLConnection.getHeaderFields() throws IllegalArgumentException: Illegal cookie name
michaelm
parents:
diff changeset
    25
 * @bug 7183292
f8aa59b3988e 7183292: HttpURLConnection.getHeaderFields() throws IllegalArgumentException: Illegal cookie name
michaelm
parents:
diff changeset
    26
 */
f8aa59b3988e 7183292: HttpURLConnection.getHeaderFields() throws IllegalArgumentException: Illegal cookie name
michaelm
parents:
diff changeset
    27
import java.net.*;
f8aa59b3988e 7183292: HttpURLConnection.getHeaderFields() throws IllegalArgumentException: Illegal cookie name
michaelm
parents:
diff changeset
    28
import java.util.*;
f8aa59b3988e 7183292: HttpURLConnection.getHeaderFields() throws IllegalArgumentException: Illegal cookie name
michaelm
parents:
diff changeset
    29
import java.io.*;
f8aa59b3988e 7183292: HttpURLConnection.getHeaderFields() throws IllegalArgumentException: Illegal cookie name
michaelm
parents:
diff changeset
    30
import com.sun.net.httpserver.*;
f8aa59b3988e 7183292: HttpURLConnection.getHeaderFields() throws IllegalArgumentException: Illegal cookie name
michaelm
parents:
diff changeset
    31
f8aa59b3988e 7183292: HttpURLConnection.getHeaderFields() throws IllegalArgumentException: Illegal cookie name
michaelm
parents:
diff changeset
    32
public class IllegalCookieNameTest {
f8aa59b3988e 7183292: HttpURLConnection.getHeaderFields() throws IllegalArgumentException: Illegal cookie name
michaelm
parents:
diff changeset
    33
    public static void main(String[] args) throws IOException {
f8aa59b3988e 7183292: HttpURLConnection.getHeaderFields() throws IllegalArgumentException: Illegal cookie name
michaelm
parents:
diff changeset
    34
        HttpServer s = null;
f8aa59b3988e 7183292: HttpURLConnection.getHeaderFields() throws IllegalArgumentException: Illegal cookie name
michaelm
parents:
diff changeset
    35
        try {
f8aa59b3988e 7183292: HttpURLConnection.getHeaderFields() throws IllegalArgumentException: Illegal cookie name
michaelm
parents:
diff changeset
    36
            InetSocketAddress addr = new InetSocketAddress(0);
f8aa59b3988e 7183292: HttpURLConnection.getHeaderFields() throws IllegalArgumentException: Illegal cookie name
michaelm
parents:
diff changeset
    37
            s = HttpServer.create(addr, 10);
f8aa59b3988e 7183292: HttpURLConnection.getHeaderFields() throws IllegalArgumentException: Illegal cookie name
michaelm
parents:
diff changeset
    38
            s.createContext("/", new HHandler());
f8aa59b3988e 7183292: HttpURLConnection.getHeaderFields() throws IllegalArgumentException: Illegal cookie name
michaelm
parents:
diff changeset
    39
            s.start();
f8aa59b3988e 7183292: HttpURLConnection.getHeaderFields() throws IllegalArgumentException: Illegal cookie name
michaelm
parents:
diff changeset
    40
            String u = "http://127.0.0.1:" + s.getAddress().getPort() + "/";
f8aa59b3988e 7183292: HttpURLConnection.getHeaderFields() throws IllegalArgumentException: Illegal cookie name
michaelm
parents:
diff changeset
    41
            CookieHandler.setDefault(new TestCookieHandler());
f8aa59b3988e 7183292: HttpURLConnection.getHeaderFields() throws IllegalArgumentException: Illegal cookie name
michaelm
parents:
diff changeset
    42
            URL url = new URL(u);
f8aa59b3988e 7183292: HttpURLConnection.getHeaderFields() throws IllegalArgumentException: Illegal cookie name
michaelm
parents:
diff changeset
    43
            HttpURLConnection c = (HttpURLConnection) url.openConnection();
f8aa59b3988e 7183292: HttpURLConnection.getHeaderFields() throws IllegalArgumentException: Illegal cookie name
michaelm
parents:
diff changeset
    44
            c.getHeaderFields();
f8aa59b3988e 7183292: HttpURLConnection.getHeaderFields() throws IllegalArgumentException: Illegal cookie name
michaelm
parents:
diff changeset
    45
            System.out.println ("OK");
f8aa59b3988e 7183292: HttpURLConnection.getHeaderFields() throws IllegalArgumentException: Illegal cookie name
michaelm
parents:
diff changeset
    46
        } finally {
f8aa59b3988e 7183292: HttpURLConnection.getHeaderFields() throws IllegalArgumentException: Illegal cookie name
michaelm
parents:
diff changeset
    47
            s.stop(1);
f8aa59b3988e 7183292: HttpURLConnection.getHeaderFields() throws IllegalArgumentException: Illegal cookie name
michaelm
parents:
diff changeset
    48
        }
f8aa59b3988e 7183292: HttpURLConnection.getHeaderFields() throws IllegalArgumentException: Illegal cookie name
michaelm
parents:
diff changeset
    49
    }
f8aa59b3988e 7183292: HttpURLConnection.getHeaderFields() throws IllegalArgumentException: Illegal cookie name
michaelm
parents:
diff changeset
    50
}
f8aa59b3988e 7183292: HttpURLConnection.getHeaderFields() throws IllegalArgumentException: Illegal cookie name
michaelm
parents:
diff changeset
    51
f8aa59b3988e 7183292: HttpURLConnection.getHeaderFields() throws IllegalArgumentException: Illegal cookie name
michaelm
parents:
diff changeset
    52
class TestCookieHandler extends CookieHandler {
f8aa59b3988e 7183292: HttpURLConnection.getHeaderFields() throws IllegalArgumentException: Illegal cookie name
michaelm
parents:
diff changeset
    53
    @Override
f8aa59b3988e 7183292: HttpURLConnection.getHeaderFields() throws IllegalArgumentException: Illegal cookie name
michaelm
parents:
diff changeset
    54
    public Map<String, List<String>> get(URI uri, Map<String, List<String>> requestHeaders) {
f8aa59b3988e 7183292: HttpURLConnection.getHeaderFields() throws IllegalArgumentException: Illegal cookie name
michaelm
parents:
diff changeset
    55
        return new HashMap<String, List<String>>();
f8aa59b3988e 7183292: HttpURLConnection.getHeaderFields() throws IllegalArgumentException: Illegal cookie name
michaelm
parents:
diff changeset
    56
    }
f8aa59b3988e 7183292: HttpURLConnection.getHeaderFields() throws IllegalArgumentException: Illegal cookie name
michaelm
parents:
diff changeset
    57
f8aa59b3988e 7183292: HttpURLConnection.getHeaderFields() throws IllegalArgumentException: Illegal cookie name
michaelm
parents:
diff changeset
    58
    @Override
f8aa59b3988e 7183292: HttpURLConnection.getHeaderFields() throws IllegalArgumentException: Illegal cookie name
michaelm
parents:
diff changeset
    59
    public void put(URI uri, Map<String, List<String>> responseHeaders) {
f8aa59b3988e 7183292: HttpURLConnection.getHeaderFields() throws IllegalArgumentException: Illegal cookie name
michaelm
parents:
diff changeset
    60
    }
f8aa59b3988e 7183292: HttpURLConnection.getHeaderFields() throws IllegalArgumentException: Illegal cookie name
michaelm
parents:
diff changeset
    61
}
f8aa59b3988e 7183292: HttpURLConnection.getHeaderFields() throws IllegalArgumentException: Illegal cookie name
michaelm
parents:
diff changeset
    62
f8aa59b3988e 7183292: HttpURLConnection.getHeaderFields() throws IllegalArgumentException: Illegal cookie name
michaelm
parents:
diff changeset
    63
class HHandler implements  HttpHandler {
f8aa59b3988e 7183292: HttpURLConnection.getHeaderFields() throws IllegalArgumentException: Illegal cookie name
michaelm
parents:
diff changeset
    64
    public void handle (HttpExchange e) {
f8aa59b3988e 7183292: HttpURLConnection.getHeaderFields() throws IllegalArgumentException: Illegal cookie name
michaelm
parents:
diff changeset
    65
        try {
f8aa59b3988e 7183292: HttpURLConnection.getHeaderFields() throws IllegalArgumentException: Illegal cookie name
michaelm
parents:
diff changeset
    66
            Headers h = e.getResponseHeaders();
f8aa59b3988e 7183292: HttpURLConnection.getHeaderFields() throws IllegalArgumentException: Illegal cookie name
michaelm
parents:
diff changeset
    67
            h.set ("Set-Cookie", "domain=; expires=Mon, 01-Jan-1990 00:00:00 GMT; path=/; domain=.foo.com");
f8aa59b3988e 7183292: HttpURLConnection.getHeaderFields() throws IllegalArgumentException: Illegal cookie name
michaelm
parents:
diff changeset
    68
            e.sendResponseHeaders(200, -1);
f8aa59b3988e 7183292: HttpURLConnection.getHeaderFields() throws IllegalArgumentException: Illegal cookie name
michaelm
parents:
diff changeset
    69
            e.close();
f8aa59b3988e 7183292: HttpURLConnection.getHeaderFields() throws IllegalArgumentException: Illegal cookie name
michaelm
parents:
diff changeset
    70
        } catch (Exception ex) {
f8aa59b3988e 7183292: HttpURLConnection.getHeaderFields() throws IllegalArgumentException: Illegal cookie name
michaelm
parents:
diff changeset
    71
            System.out.println (ex);
f8aa59b3988e 7183292: HttpURLConnection.getHeaderFields() throws IllegalArgumentException: Illegal cookie name
michaelm
parents:
diff changeset
    72
        }
f8aa59b3988e 7183292: HttpURLConnection.getHeaderFields() throws IllegalArgumentException: Illegal cookie name
michaelm
parents:
diff changeset
    73
    }
f8aa59b3988e 7183292: HttpURLConnection.getHeaderFields() throws IllegalArgumentException: Illegal cookie name
michaelm
parents:
diff changeset
    74
}