Skip to content

Commit b73faca

Browse files
8235976: Directives in WWW-Authenticate should be comma separated
Reviewed-by: chegar
1 parent 49048ad commit b73faca

File tree

2 files changed

+14
-12
lines changed

2 files changed

+14
-12
lines changed

src/jdk.httpserver/share/classes/com/sun/net/httpserver/BasicAuthenticator.java

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -95,10 +95,7 @@ public Result authenticate (HttpExchange t)
9595
*/
9696
String auth = rmap.getFirst ("Authorization");
9797
if (auth == null) {
98-
Headers map = t.getResponseHeaders();
99-
var authString = "Basic realm=" + "\"" + realm + "\"" +
100-
(isUTF8 ? " charset=\"UTF-8\"" : "");
101-
map.set ("WWW-Authenticate", authString);
98+
setAuthHeader(t);
10299
return new Authenticator.Retry (401);
103100
}
104101
int sp = auth.indexOf (' ');
@@ -119,13 +116,18 @@ public Result authenticate (HttpExchange t)
119116
);
120117
} else {
121118
/* reject the request again with 401 */
122-
123-
Headers map = t.getResponseHeaders();
124-
map.set ("WWW-Authenticate", "Basic realm=" + "\""+realm+"\"");
119+
setAuthHeader(t);
125120
return new Authenticator.Failure(401);
126121
}
127122
}
128123

124+
private void setAuthHeader(HttpExchange t) {
125+
Headers map = t.getResponseHeaders();
126+
var authString = "Basic realm=" + "\"" + realm + "\"" +
127+
(isUTF8 ? ", charset=\"UTF-8\"" : "");
128+
map.set ("WWW-Authenticate", authString);
129+
}
130+
129131
/**
130132
* called for each incoming request to verify the
131133
* given name and password in the context of this

test/jdk/com/sun/net/httpserver/bugs/8199849/ParamTest.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232

3333
/**
3434
* @test
35-
* @bug 8199849
35+
* @bug 8199849 8235976
3636
* @summary
3737
* @library /test/lib
3838
* @run main/othervm ParamTest
@@ -42,10 +42,10 @@
4242
public class ParamTest {
4343

4444
static final String[] variants = {
45-
" charset=utf-8",
46-
" charset=UtF-8",
47-
" charset=\"utF-8\"",
48-
" charset=\"UtF-8\""
45+
" ,charset=utf-8",
46+
" ,charset=UtF-8",
47+
" ,charset=\"utF-8\"",
48+
" ,charset=\"UtF-8\""
4949
};
5050

5151
static final int LOOPS = variants.length;

0 commit comments

Comments
 (0)