author | jboes |
Fri, 08 Nov 2019 11:15:16 +0000 | |
changeset 59029 | 3786a0962570 |
parent 54314 | 46cf212cdcca |
permissions | -rw-r--r-- |
53374
7c0d1f696dbc
8217237: HttpClient does not deal well with multi-valued WWW-Authenticate challenge headers
michaelm
parents:
diff
changeset
|
1 |
/* |
7c0d1f696dbc
8217237: HttpClient does not deal well with multi-valued WWW-Authenticate challenge headers
michaelm
parents:
diff
changeset
|
2 |
* Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved. |
7c0d1f696dbc
8217237: HttpClient does not deal well with multi-valued WWW-Authenticate challenge headers
michaelm
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
7c0d1f696dbc
8217237: HttpClient does not deal well with multi-valued WWW-Authenticate challenge headers
michaelm
parents:
diff
changeset
|
4 |
* |
7c0d1f696dbc
8217237: HttpClient does not deal well with multi-valued WWW-Authenticate challenge headers
michaelm
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
7c0d1f696dbc
8217237: HttpClient does not deal well with multi-valued WWW-Authenticate challenge headers
michaelm
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
7c0d1f696dbc
8217237: HttpClient does not deal well with multi-valued WWW-Authenticate challenge headers
michaelm
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
7c0d1f696dbc
8217237: HttpClient does not deal well with multi-valued WWW-Authenticate challenge headers
michaelm
parents:
diff
changeset
|
8 |
* |
7c0d1f696dbc
8217237: HttpClient does not deal well with multi-valued WWW-Authenticate challenge headers
michaelm
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
7c0d1f696dbc
8217237: HttpClient does not deal well with multi-valued WWW-Authenticate challenge headers
michaelm
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
7c0d1f696dbc
8217237: HttpClient does not deal well with multi-valued WWW-Authenticate challenge headers
michaelm
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
7c0d1f696dbc
8217237: HttpClient does not deal well with multi-valued WWW-Authenticate challenge headers
michaelm
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
7c0d1f696dbc
8217237: HttpClient does not deal well with multi-valued WWW-Authenticate challenge headers
michaelm
parents:
diff
changeset
|
13 |
* accompanied this code). |
7c0d1f696dbc
8217237: HttpClient does not deal well with multi-valued WWW-Authenticate challenge headers
michaelm
parents:
diff
changeset
|
14 |
* |
7c0d1f696dbc
8217237: HttpClient does not deal well with multi-valued WWW-Authenticate challenge headers
michaelm
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
7c0d1f696dbc
8217237: HttpClient does not deal well with multi-valued WWW-Authenticate challenge headers
michaelm
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
7c0d1f696dbc
8217237: HttpClient does not deal well with multi-valued WWW-Authenticate challenge headers
michaelm
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
7c0d1f696dbc
8217237: HttpClient does not deal well with multi-valued WWW-Authenticate challenge headers
michaelm
parents:
diff
changeset
|
18 |
* |
7c0d1f696dbc
8217237: HttpClient does not deal well with multi-valued WWW-Authenticate challenge headers
michaelm
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
7c0d1f696dbc
8217237: HttpClient does not deal well with multi-valued WWW-Authenticate challenge headers
michaelm
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
7c0d1f696dbc
8217237: HttpClient does not deal well with multi-valued WWW-Authenticate challenge headers
michaelm
parents:
diff
changeset
|
21 |
* questions. |
7c0d1f696dbc
8217237: HttpClient does not deal well with multi-valued WWW-Authenticate challenge headers
michaelm
parents:
diff
changeset
|
22 |
*/ |
7c0d1f696dbc
8217237: HttpClient does not deal well with multi-valued WWW-Authenticate challenge headers
michaelm
parents:
diff
changeset
|
23 |
|
7c0d1f696dbc
8217237: HttpClient does not deal well with multi-valued WWW-Authenticate challenge headers
michaelm
parents:
diff
changeset
|
24 |
/** |
7c0d1f696dbc
8217237: HttpClient does not deal well with multi-valued WWW-Authenticate challenge headers
michaelm
parents:
diff
changeset
|
25 |
* @test |
7c0d1f696dbc
8217237: HttpClient does not deal well with multi-valued WWW-Authenticate challenge headers
michaelm
parents:
diff
changeset
|
26 |
* @bug 8217237 |
54314
46cf212cdcca
8220575: Replace hardcoded 127.0.0.1 in URLs with new URI builder
aeubanks
parents:
53374
diff
changeset
|
27 |
* @library /test/lib |
53374
7c0d1f696dbc
8217237: HttpClient does not deal well with multi-valued WWW-Authenticate challenge headers
michaelm
parents:
diff
changeset
|
28 |
* @modules java.net.http |
7c0d1f696dbc
8217237: HttpClient does not deal well with multi-valued WWW-Authenticate challenge headers
michaelm
parents:
diff
changeset
|
29 |
* @run main/othervm AuthSchemesTest |
7c0d1f696dbc
8217237: HttpClient does not deal well with multi-valued WWW-Authenticate challenge headers
michaelm
parents:
diff
changeset
|
30 |
* @summary HttpClient does not deal well with multi-valued WWW-Authenticate challenge headers |
7c0d1f696dbc
8217237: HttpClient does not deal well with multi-valued WWW-Authenticate challenge headers
michaelm
parents:
diff
changeset
|
31 |
*/ |
7c0d1f696dbc
8217237: HttpClient does not deal well with multi-valued WWW-Authenticate challenge headers
michaelm
parents:
diff
changeset
|
32 |
|
7c0d1f696dbc
8217237: HttpClient does not deal well with multi-valued WWW-Authenticate challenge headers
michaelm
parents:
diff
changeset
|
33 |
import java.io.IOException; |
7c0d1f696dbc
8217237: HttpClient does not deal well with multi-valued WWW-Authenticate challenge headers
michaelm
parents:
diff
changeset
|
34 |
import java.io.InputStream; |
7c0d1f696dbc
8217237: HttpClient does not deal well with multi-valued WWW-Authenticate challenge headers
michaelm
parents:
diff
changeset
|
35 |
import java.io.OutputStream; |
7c0d1f696dbc
8217237: HttpClient does not deal well with multi-valued WWW-Authenticate challenge headers
michaelm
parents:
diff
changeset
|
36 |
import java.net.*; |
7c0d1f696dbc
8217237: HttpClient does not deal well with multi-valued WWW-Authenticate challenge headers
michaelm
parents:
diff
changeset
|
37 |
import java.net.Authenticator; |
7c0d1f696dbc
8217237: HttpClient does not deal well with multi-valued WWW-Authenticate challenge headers
michaelm
parents:
diff
changeset
|
38 |
import java.net.http.HttpClient; |
7c0d1f696dbc
8217237: HttpClient does not deal well with multi-valued WWW-Authenticate challenge headers
michaelm
parents:
diff
changeset
|
39 |
import java.net.http.HttpRequest; |
7c0d1f696dbc
8217237: HttpClient does not deal well with multi-valued WWW-Authenticate challenge headers
michaelm
parents:
diff
changeset
|
40 |
import java.net.http.HttpResponse; |
54314
46cf212cdcca
8220575: Replace hardcoded 127.0.0.1 in URLs with new URI builder
aeubanks
parents:
53374
diff
changeset
|
41 |
import jdk.test.lib.net.URIBuilder; |
53374
7c0d1f696dbc
8217237: HttpClient does not deal well with multi-valued WWW-Authenticate challenge headers
michaelm
parents:
diff
changeset
|
42 |
|
7c0d1f696dbc
8217237: HttpClient does not deal well with multi-valued WWW-Authenticate challenge headers
michaelm
parents:
diff
changeset
|
43 |
public class AuthSchemesTest { |
7c0d1f696dbc
8217237: HttpClient does not deal well with multi-valued WWW-Authenticate challenge headers
michaelm
parents:
diff
changeset
|
44 |
static class BasicServer extends Thread { |
7c0d1f696dbc
8217237: HttpClient does not deal well with multi-valued WWW-Authenticate challenge headers
michaelm
parents:
diff
changeset
|
45 |
|
7c0d1f696dbc
8217237: HttpClient does not deal well with multi-valued WWW-Authenticate challenge headers
michaelm
parents:
diff
changeset
|
46 |
ServerSocket server; |
7c0d1f696dbc
8217237: HttpClient does not deal well with multi-valued WWW-Authenticate challenge headers
michaelm
parents:
diff
changeset
|
47 |
|
7c0d1f696dbc
8217237: HttpClient does not deal well with multi-valued WWW-Authenticate challenge headers
michaelm
parents:
diff
changeset
|
48 |
Socket s; |
7c0d1f696dbc
8217237: HttpClient does not deal well with multi-valued WWW-Authenticate challenge headers
michaelm
parents:
diff
changeset
|
49 |
InputStream is; |
7c0d1f696dbc
8217237: HttpClient does not deal well with multi-valued WWW-Authenticate challenge headers
michaelm
parents:
diff
changeset
|
50 |
OutputStream os; |
7c0d1f696dbc
8217237: HttpClient does not deal well with multi-valued WWW-Authenticate challenge headers
michaelm
parents:
diff
changeset
|
51 |
static final String RESPONSE = "Hello world"; |
7c0d1f696dbc
8217237: HttpClient does not deal well with multi-valued WWW-Authenticate challenge headers
michaelm
parents:
diff
changeset
|
52 |
static final String respLength = Integer.toString(RESPONSE.length()); |
7c0d1f696dbc
8217237: HttpClient does not deal well with multi-valued WWW-Authenticate challenge headers
michaelm
parents:
diff
changeset
|
53 |
static final String realm = "wally world"; |
7c0d1f696dbc
8217237: HttpClient does not deal well with multi-valued WWW-Authenticate challenge headers
michaelm
parents:
diff
changeset
|
54 |
|
7c0d1f696dbc
8217237: HttpClient does not deal well with multi-valued WWW-Authenticate challenge headers
michaelm
parents:
diff
changeset
|
55 |
String reply1 = "HTTP/1.1 401 Unauthorized\r\n"+ |
7c0d1f696dbc
8217237: HttpClient does not deal well with multi-valued WWW-Authenticate challenge headers
michaelm
parents:
diff
changeset
|
56 |
"WWW-Authenticate: BarScheme\r\n" + |
7c0d1f696dbc
8217237: HttpClient does not deal well with multi-valued WWW-Authenticate challenge headers
michaelm
parents:
diff
changeset
|
57 |
"WWW-Authenticate: FooScheme realm=\""+realm+"\"\r\n" + |
7c0d1f696dbc
8217237: HttpClient does not deal well with multi-valued WWW-Authenticate challenge headers
michaelm
parents:
diff
changeset
|
58 |
"WWW-Authenticate: Basic realm=\""+realm+"\"\r\n" + |
7c0d1f696dbc
8217237: HttpClient does not deal well with multi-valued WWW-Authenticate challenge headers
michaelm
parents:
diff
changeset
|
59 |
"WWW-Authenticate: WoofScheme\r\n\r\n"; |
7c0d1f696dbc
8217237: HttpClient does not deal well with multi-valued WWW-Authenticate challenge headers
michaelm
parents:
diff
changeset
|
60 |
|
7c0d1f696dbc
8217237: HttpClient does not deal well with multi-valued WWW-Authenticate challenge headers
michaelm
parents:
diff
changeset
|
61 |
String reply2 = "HTTP/1.1 200 OK\r\n"+ |
7c0d1f696dbc
8217237: HttpClient does not deal well with multi-valued WWW-Authenticate challenge headers
michaelm
parents:
diff
changeset
|
62 |
"Date: Mon, 15 Jan 2001 12:18:21 GMT\r\n" + |
7c0d1f696dbc
8217237: HttpClient does not deal well with multi-valued WWW-Authenticate challenge headers
michaelm
parents:
diff
changeset
|
63 |
"Server: Apache/1.3.14 (Unix)\r\n" + |
7c0d1f696dbc
8217237: HttpClient does not deal well with multi-valued WWW-Authenticate challenge headers
michaelm
parents:
diff
changeset
|
64 |
"Connection: close\r\n" + |
7c0d1f696dbc
8217237: HttpClient does not deal well with multi-valued WWW-Authenticate challenge headers
michaelm
parents:
diff
changeset
|
65 |
"Content-Type: text/html; charset=iso-8859-1\r\n" + |
7c0d1f696dbc
8217237: HttpClient does not deal well with multi-valued WWW-Authenticate challenge headers
michaelm
parents:
diff
changeset
|
66 |
"Content-Length: " + respLength + "\r\n\r\n"; |
7c0d1f696dbc
8217237: HttpClient does not deal well with multi-valued WWW-Authenticate challenge headers
michaelm
parents:
diff
changeset
|
67 |
|
7c0d1f696dbc
8217237: HttpClient does not deal well with multi-valued WWW-Authenticate challenge headers
michaelm
parents:
diff
changeset
|
68 |
BasicServer(ServerSocket s) { |
7c0d1f696dbc
8217237: HttpClient does not deal well with multi-valued WWW-Authenticate challenge headers
michaelm
parents:
diff
changeset
|
69 |
server = s; |
7c0d1f696dbc
8217237: HttpClient does not deal well with multi-valued WWW-Authenticate challenge headers
michaelm
parents:
diff
changeset
|
70 |
} |
7c0d1f696dbc
8217237: HttpClient does not deal well with multi-valued WWW-Authenticate challenge headers
michaelm
parents:
diff
changeset
|
71 |
|
7c0d1f696dbc
8217237: HttpClient does not deal well with multi-valued WWW-Authenticate challenge headers
michaelm
parents:
diff
changeset
|
72 |
String response() { |
7c0d1f696dbc
8217237: HttpClient does not deal well with multi-valued WWW-Authenticate challenge headers
michaelm
parents:
diff
changeset
|
73 |
return RESPONSE; |
7c0d1f696dbc
8217237: HttpClient does not deal well with multi-valued WWW-Authenticate challenge headers
michaelm
parents:
diff
changeset
|
74 |
} |
7c0d1f696dbc
8217237: HttpClient does not deal well with multi-valued WWW-Authenticate challenge headers
michaelm
parents:
diff
changeset
|
75 |
|
7c0d1f696dbc
8217237: HttpClient does not deal well with multi-valued WWW-Authenticate challenge headers
michaelm
parents:
diff
changeset
|
76 |
void readAll(Socket s) throws IOException { |
7c0d1f696dbc
8217237: HttpClient does not deal well with multi-valued WWW-Authenticate challenge headers
michaelm
parents:
diff
changeset
|
77 |
byte[] buf = new byte [128]; |
7c0d1f696dbc
8217237: HttpClient does not deal well with multi-valued WWW-Authenticate challenge headers
michaelm
parents:
diff
changeset
|
78 |
InputStream is = s.getInputStream(); |
7c0d1f696dbc
8217237: HttpClient does not deal well with multi-valued WWW-Authenticate challenge headers
michaelm
parents:
diff
changeset
|
79 |
s.setSoTimeout(1000); |
7c0d1f696dbc
8217237: HttpClient does not deal well with multi-valued WWW-Authenticate challenge headers
michaelm
parents:
diff
changeset
|
80 |
try { |
7c0d1f696dbc
8217237: HttpClient does not deal well with multi-valued WWW-Authenticate challenge headers
michaelm
parents:
diff
changeset
|
81 |
while (is.read(buf) > 0) ; |
7c0d1f696dbc
8217237: HttpClient does not deal well with multi-valued WWW-Authenticate challenge headers
michaelm
parents:
diff
changeset
|
82 |
} catch (SocketTimeoutException x) { } |
7c0d1f696dbc
8217237: HttpClient does not deal well with multi-valued WWW-Authenticate challenge headers
michaelm
parents:
diff
changeset
|
83 |
} |
7c0d1f696dbc
8217237: HttpClient does not deal well with multi-valued WWW-Authenticate challenge headers
michaelm
parents:
diff
changeset
|
84 |
|
7c0d1f696dbc
8217237: HttpClient does not deal well with multi-valued WWW-Authenticate challenge headers
michaelm
parents:
diff
changeset
|
85 |
public void run() { |
7c0d1f696dbc
8217237: HttpClient does not deal well with multi-valued WWW-Authenticate challenge headers
michaelm
parents:
diff
changeset
|
86 |
try { |
7c0d1f696dbc
8217237: HttpClient does not deal well with multi-valued WWW-Authenticate challenge headers
michaelm
parents:
diff
changeset
|
87 |
System.out.println("Server 1: accept"); |
7c0d1f696dbc
8217237: HttpClient does not deal well with multi-valued WWW-Authenticate challenge headers
michaelm
parents:
diff
changeset
|
88 |
s = server.accept(); |
7c0d1f696dbc
8217237: HttpClient does not deal well with multi-valued WWW-Authenticate challenge headers
michaelm
parents:
diff
changeset
|
89 |
System.out.println("accepted"); |
7c0d1f696dbc
8217237: HttpClient does not deal well with multi-valued WWW-Authenticate challenge headers
michaelm
parents:
diff
changeset
|
90 |
os = s.getOutputStream(); |
7c0d1f696dbc
8217237: HttpClient does not deal well with multi-valued WWW-Authenticate challenge headers
michaelm
parents:
diff
changeset
|
91 |
os.write(reply1.getBytes()); |
7c0d1f696dbc
8217237: HttpClient does not deal well with multi-valued WWW-Authenticate challenge headers
michaelm
parents:
diff
changeset
|
92 |
readAll(s); |
7c0d1f696dbc
8217237: HttpClient does not deal well with multi-valued WWW-Authenticate challenge headers
michaelm
parents:
diff
changeset
|
93 |
s.close(); |
7c0d1f696dbc
8217237: HttpClient does not deal well with multi-valued WWW-Authenticate challenge headers
michaelm
parents:
diff
changeset
|
94 |
|
7c0d1f696dbc
8217237: HttpClient does not deal well with multi-valued WWW-Authenticate challenge headers
michaelm
parents:
diff
changeset
|
95 |
System.out.println("Server 2: accept"); |
7c0d1f696dbc
8217237: HttpClient does not deal well with multi-valued WWW-Authenticate challenge headers
michaelm
parents:
diff
changeset
|
96 |
s = server.accept(); |
7c0d1f696dbc
8217237: HttpClient does not deal well with multi-valued WWW-Authenticate challenge headers
michaelm
parents:
diff
changeset
|
97 |
System.out.println("accepted"); |
7c0d1f696dbc
8217237: HttpClient does not deal well with multi-valued WWW-Authenticate challenge headers
michaelm
parents:
diff
changeset
|
98 |
os = s.getOutputStream(); |
7c0d1f696dbc
8217237: HttpClient does not deal well with multi-valued WWW-Authenticate challenge headers
michaelm
parents:
diff
changeset
|
99 |
os.write((reply2+RESPONSE).getBytes()); |
7c0d1f696dbc
8217237: HttpClient does not deal well with multi-valued WWW-Authenticate challenge headers
michaelm
parents:
diff
changeset
|
100 |
readAll(s); |
7c0d1f696dbc
8217237: HttpClient does not deal well with multi-valued WWW-Authenticate challenge headers
michaelm
parents:
diff
changeset
|
101 |
s.close(); |
7c0d1f696dbc
8217237: HttpClient does not deal well with multi-valued WWW-Authenticate challenge headers
michaelm
parents:
diff
changeset
|
102 |
|
7c0d1f696dbc
8217237: HttpClient does not deal well with multi-valued WWW-Authenticate challenge headers
michaelm
parents:
diff
changeset
|
103 |
} |
7c0d1f696dbc
8217237: HttpClient does not deal well with multi-valued WWW-Authenticate challenge headers
michaelm
parents:
diff
changeset
|
104 |
catch (Exception e) { |
7c0d1f696dbc
8217237: HttpClient does not deal well with multi-valued WWW-Authenticate challenge headers
michaelm
parents:
diff
changeset
|
105 |
System.out.println(e); |
7c0d1f696dbc
8217237: HttpClient does not deal well with multi-valued WWW-Authenticate challenge headers
michaelm
parents:
diff
changeset
|
106 |
} |
7c0d1f696dbc
8217237: HttpClient does not deal well with multi-valued WWW-Authenticate challenge headers
michaelm
parents:
diff
changeset
|
107 |
finished(); |
7c0d1f696dbc
8217237: HttpClient does not deal well with multi-valued WWW-Authenticate challenge headers
michaelm
parents:
diff
changeset
|
108 |
} |
7c0d1f696dbc
8217237: HttpClient does not deal well with multi-valued WWW-Authenticate challenge headers
michaelm
parents:
diff
changeset
|
109 |
|
7c0d1f696dbc
8217237: HttpClient does not deal well with multi-valued WWW-Authenticate challenge headers
michaelm
parents:
diff
changeset
|
110 |
boolean isfinished = false; |
7c0d1f696dbc
8217237: HttpClient does not deal well with multi-valued WWW-Authenticate challenge headers
michaelm
parents:
diff
changeset
|
111 |
|
7c0d1f696dbc
8217237: HttpClient does not deal well with multi-valued WWW-Authenticate challenge headers
michaelm
parents:
diff
changeset
|
112 |
public synchronized void finished() { |
7c0d1f696dbc
8217237: HttpClient does not deal well with multi-valued WWW-Authenticate challenge headers
michaelm
parents:
diff
changeset
|
113 |
isfinished = true; |
7c0d1f696dbc
8217237: HttpClient does not deal well with multi-valued WWW-Authenticate challenge headers
michaelm
parents:
diff
changeset
|
114 |
notifyAll(); |
7c0d1f696dbc
8217237: HttpClient does not deal well with multi-valued WWW-Authenticate challenge headers
michaelm
parents:
diff
changeset
|
115 |
} |
7c0d1f696dbc
8217237: HttpClient does not deal well with multi-valued WWW-Authenticate challenge headers
michaelm
parents:
diff
changeset
|
116 |
|
7c0d1f696dbc
8217237: HttpClient does not deal well with multi-valued WWW-Authenticate challenge headers
michaelm
parents:
diff
changeset
|
117 |
public synchronized void waitforfinish() { |
7c0d1f696dbc
8217237: HttpClient does not deal well with multi-valued WWW-Authenticate challenge headers
michaelm
parents:
diff
changeset
|
118 |
while (!isfinished) { |
7c0d1f696dbc
8217237: HttpClient does not deal well with multi-valued WWW-Authenticate challenge headers
michaelm
parents:
diff
changeset
|
119 |
try { |
7c0d1f696dbc
8217237: HttpClient does not deal well with multi-valued WWW-Authenticate challenge headers
michaelm
parents:
diff
changeset
|
120 |
wait(); |
7c0d1f696dbc
8217237: HttpClient does not deal well with multi-valued WWW-Authenticate challenge headers
michaelm
parents:
diff
changeset
|
121 |
} catch (InterruptedException e) { |
7c0d1f696dbc
8217237: HttpClient does not deal well with multi-valued WWW-Authenticate challenge headers
michaelm
parents:
diff
changeset
|
122 |
e.printStackTrace(); |
7c0d1f696dbc
8217237: HttpClient does not deal well with multi-valued WWW-Authenticate challenge headers
michaelm
parents:
diff
changeset
|
123 |
} |
7c0d1f696dbc
8217237: HttpClient does not deal well with multi-valued WWW-Authenticate challenge headers
michaelm
parents:
diff
changeset
|
124 |
} |
7c0d1f696dbc
8217237: HttpClient does not deal well with multi-valued WWW-Authenticate challenge headers
michaelm
parents:
diff
changeset
|
125 |
} |
7c0d1f696dbc
8217237: HttpClient does not deal well with multi-valued WWW-Authenticate challenge headers
michaelm
parents:
diff
changeset
|
126 |
} |
7c0d1f696dbc
8217237: HttpClient does not deal well with multi-valued WWW-Authenticate challenge headers
michaelm
parents:
diff
changeset
|
127 |
|
7c0d1f696dbc
8217237: HttpClient does not deal well with multi-valued WWW-Authenticate challenge headers
michaelm
parents:
diff
changeset
|
128 |
static class Auth extends Authenticator { |
7c0d1f696dbc
8217237: HttpClient does not deal well with multi-valued WWW-Authenticate challenge headers
michaelm
parents:
diff
changeset
|
129 |
protected PasswordAuthentication getPasswordAuthentication() { |
7c0d1f696dbc
8217237: HttpClient does not deal well with multi-valued WWW-Authenticate challenge headers
michaelm
parents:
diff
changeset
|
130 |
return new PasswordAuthentication("user", new char[] {'a','b','c'}); |
7c0d1f696dbc
8217237: HttpClient does not deal well with multi-valued WWW-Authenticate challenge headers
michaelm
parents:
diff
changeset
|
131 |
} |
7c0d1f696dbc
8217237: HttpClient does not deal well with multi-valued WWW-Authenticate challenge headers
michaelm
parents:
diff
changeset
|
132 |
} |
7c0d1f696dbc
8217237: HttpClient does not deal well with multi-valued WWW-Authenticate challenge headers
michaelm
parents:
diff
changeset
|
133 |
|
7c0d1f696dbc
8217237: HttpClient does not deal well with multi-valued WWW-Authenticate challenge headers
michaelm
parents:
diff
changeset
|
134 |
public static void main(String[] args) throws Exception { |
7c0d1f696dbc
8217237: HttpClient does not deal well with multi-valued WWW-Authenticate challenge headers
michaelm
parents:
diff
changeset
|
135 |
ServerSocket serversocket = null; |
7c0d1f696dbc
8217237: HttpClient does not deal well with multi-valued WWW-Authenticate challenge headers
michaelm
parents:
diff
changeset
|
136 |
BasicServer server = null; |
7c0d1f696dbc
8217237: HttpClient does not deal well with multi-valued WWW-Authenticate challenge headers
michaelm
parents:
diff
changeset
|
137 |
Auth authenticator = new Auth(); |
7c0d1f696dbc
8217237: HttpClient does not deal well with multi-valued WWW-Authenticate challenge headers
michaelm
parents:
diff
changeset
|
138 |
|
7c0d1f696dbc
8217237: HttpClient does not deal well with multi-valued WWW-Authenticate challenge headers
michaelm
parents:
diff
changeset
|
139 |
serversocket = new ServerSocket(0, 10, InetAddress.getLoopbackAddress()); |
7c0d1f696dbc
8217237: HttpClient does not deal well with multi-valued WWW-Authenticate challenge headers
michaelm
parents:
diff
changeset
|
140 |
int port = serversocket.getLocalPort(); |
7c0d1f696dbc
8217237: HttpClient does not deal well with multi-valued WWW-Authenticate challenge headers
michaelm
parents:
diff
changeset
|
141 |
server = new BasicServer(serversocket); |
7c0d1f696dbc
8217237: HttpClient does not deal well with multi-valued WWW-Authenticate challenge headers
michaelm
parents:
diff
changeset
|
142 |
|
7c0d1f696dbc
8217237: HttpClient does not deal well with multi-valued WWW-Authenticate challenge headers
michaelm
parents:
diff
changeset
|
143 |
HttpClient client = HttpClient.newBuilder() |
7c0d1f696dbc
8217237: HttpClient does not deal well with multi-valued WWW-Authenticate challenge headers
michaelm
parents:
diff
changeset
|
144 |
.authenticator(authenticator) |
7c0d1f696dbc
8217237: HttpClient does not deal well with multi-valued WWW-Authenticate challenge headers
michaelm
parents:
diff
changeset
|
145 |
.build(); |
7c0d1f696dbc
8217237: HttpClient does not deal well with multi-valued WWW-Authenticate challenge headers
michaelm
parents:
diff
changeset
|
146 |
server.start(); |
54314
46cf212cdcca
8220575: Replace hardcoded 127.0.0.1 in URLs with new URI builder
aeubanks
parents:
53374
diff
changeset
|
147 |
URI uri = URIBuilder.newBuilder() |
46cf212cdcca
8220575: Replace hardcoded 127.0.0.1 in URLs with new URI builder
aeubanks
parents:
53374
diff
changeset
|
148 |
.scheme("http") |
46cf212cdcca
8220575: Replace hardcoded 127.0.0.1 in URLs with new URI builder
aeubanks
parents:
53374
diff
changeset
|
149 |
.loopback() |
46cf212cdcca
8220575: Replace hardcoded 127.0.0.1 in URLs with new URI builder
aeubanks
parents:
53374
diff
changeset
|
150 |
.port(port) |
46cf212cdcca
8220575: Replace hardcoded 127.0.0.1 in URLs with new URI builder
aeubanks
parents:
53374
diff
changeset
|
151 |
.path("/foo") |
46cf212cdcca
8220575: Replace hardcoded 127.0.0.1 in URLs with new URI builder
aeubanks
parents:
53374
diff
changeset
|
152 |
.build(); |
46cf212cdcca
8220575: Replace hardcoded 127.0.0.1 in URLs with new URI builder
aeubanks
parents:
53374
diff
changeset
|
153 |
System.out.println("URI: " + uri); |
53374
7c0d1f696dbc
8217237: HttpClient does not deal well with multi-valued WWW-Authenticate challenge headers
michaelm
parents:
diff
changeset
|
154 |
HttpRequest request = HttpRequest.newBuilder(uri) |
7c0d1f696dbc
8217237: HttpClient does not deal well with multi-valued WWW-Authenticate challenge headers
michaelm
parents:
diff
changeset
|
155 |
.GET() |
7c0d1f696dbc
8217237: HttpClient does not deal well with multi-valued WWW-Authenticate challenge headers
michaelm
parents:
diff
changeset
|
156 |
.build(); |
7c0d1f696dbc
8217237: HttpClient does not deal well with multi-valued WWW-Authenticate challenge headers
michaelm
parents:
diff
changeset
|
157 |
HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString()); |
7c0d1f696dbc
8217237: HttpClient does not deal well with multi-valued WWW-Authenticate challenge headers
michaelm
parents:
diff
changeset
|
158 |
if (response.statusCode() != 200 || !response.body().equals(server.response())) { |
7c0d1f696dbc
8217237: HttpClient does not deal well with multi-valued WWW-Authenticate challenge headers
michaelm
parents:
diff
changeset
|
159 |
System.out.println("Status code = " + response.statusCode()); |
7c0d1f696dbc
8217237: HttpClient does not deal well with multi-valued WWW-Authenticate challenge headers
michaelm
parents:
diff
changeset
|
160 |
serversocket.close(); |
7c0d1f696dbc
8217237: HttpClient does not deal well with multi-valued WWW-Authenticate challenge headers
michaelm
parents:
diff
changeset
|
161 |
throw new RuntimeException("Test failed"); |
7c0d1f696dbc
8217237: HttpClient does not deal well with multi-valued WWW-Authenticate challenge headers
michaelm
parents:
diff
changeset
|
162 |
} |
7c0d1f696dbc
8217237: HttpClient does not deal well with multi-valued WWW-Authenticate challenge headers
michaelm
parents:
diff
changeset
|
163 |
serversocket.close(); |
7c0d1f696dbc
8217237: HttpClient does not deal well with multi-valued WWW-Authenticate challenge headers
michaelm
parents:
diff
changeset
|
164 |
server.waitforfinish(); |
7c0d1f696dbc
8217237: HttpClient does not deal well with multi-valued WWW-Authenticate challenge headers
michaelm
parents:
diff
changeset
|
165 |
System.out.println("OK"); |
7c0d1f696dbc
8217237: HttpClient does not deal well with multi-valued WWW-Authenticate challenge headers
michaelm
parents:
diff
changeset
|
166 |
} |
7c0d1f696dbc
8217237: HttpClient does not deal well with multi-valued WWW-Authenticate challenge headers
michaelm
parents:
diff
changeset
|
167 |
} |