Skip to content

Commit 28796cb

Browse files
djelinskiMichael-Mc-Mahon
authored andcommitted
8163921: HttpURLConnection default Accept header is malformed according to HTTP/1.1 RFC
Reviewed-by: dfuchs, michaelm
1 parent c43ce85 commit 28796cb

File tree

2 files changed

+10
-11
lines changed

2 files changed

+10
-11
lines changed

src/java.base/share/classes/sun/net/www/protocol/http/HttpURLConnection.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 1995, 2021, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 1995, 2022, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -288,8 +288,7 @@ private static Set<String> schemesListToSet(String list) {
288288
}
289289

290290
static final String httpVersion = "HTTP/1.1";
291-
static final String acceptString =
292-
"text/html, image/gif, image/jpeg, *; q=.2, */*; q=.2";
291+
static final String acceptString = "*/*";
293292

294293
// the following http request headers should NOT have their values
295294
// returned for security reasons.

test/jdk/sun/net/www/B8185898.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2019, 2022, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -23,7 +23,7 @@
2323

2424
/**
2525
* @test
26-
* @bug 8185898
26+
* @bug 8185898 8163921
2727
* @modules java.base/sun.net.www
2828
* @library /test/lib
2929
* @run main/othervm B8185898
@@ -143,32 +143,32 @@ static void testMessageHeaderMethods() throws IOException {
143143
// {{inputString1, expectedToString1, expectedPrint1}, {...}}
144144
String[][] strings = {
145145
{"HTTP/1.1 200 OK\r\n"
146-
+ "Accept: text/html, image/gif, image/jpeg, *; q=.2, */*; q=.2\r\n"
146+
+ "Accept: */*\r\n"
147147
+ "Connection: keep-alive\r\n"
148148
+ "Host: 127.0.0.1:12345\r\n"
149149
+ "User-agent: Java/12\r\n\r\nfoooo",
150150
"pairs: {null: HTTP/1.1 200 OK}"
151-
+ "{Accept: text/html, image/gif, image/jpeg, *; q=.2, */*; q=.2}"
151+
+ "{Accept: */*}"
152152
+ "{Connection: keep-alive}"
153153
+ "{Host: 127.0.0.1:12345}"
154154
+ "{User-agent: Java/12}",
155-
"Accept: text/html, image/gif, image/jpeg, *; q=.2, */*; q=.2\r\n"
155+
"Accept: */*\r\n"
156156
+ "Connection: keep-alive\r\n"
157157
+ "Host: 127.0.0.1:12345\r\n"
158158
+ "User-agent: Java/12\r\n\r\n"},
159159
{"HTTP/1.1 200 OK\r\n"
160-
+ "Accept: text/html, image/gif, image/jpeg, *; q=.2, */*; q=.2\r\n"
160+
+ "Accept: */*\r\n"
161161
+ "Connection: keep-alive\r\n"
162162
+ "Host: 127.0.0.1:12345\r\n"
163163
+ "User-agent: Java/12\r\n"
164164
+ "X-Header:\r\n\r\n",
165165
"pairs: {null: HTTP/1.1 200 OK}"
166-
+ "{Accept: text/html, image/gif, image/jpeg, *; q=.2, */*; q=.2}"
166+
+ "{Accept: */*}"
167167
+ "{Connection: keep-alive}"
168168
+ "{Host: 127.0.0.1:12345}"
169169
+ "{User-agent: Java/12}"
170170
+ "{X-Header: }",
171-
"Accept: text/html, image/gif, image/jpeg, *; q=.2, */*; q=.2\r\n"
171+
"Accept: */*\r\n"
172172
+ "Connection: keep-alive\r\n"
173173
+ "Host: 127.0.0.1:12345\r\n"
174174
+ "User-agent: Java/12\r\n"

0 commit comments

Comments
 (0)