Skip to content

Commit 3d7f5da

Browse files
committed
Use lowercase for charsets #11741
Fix #11741 as per the WhatTFWG recommendations, use lower case for charset names. Took the opportunity for some minor optimizations: + use the already made HttpField instance in MimeTypes.Type rather than create a new one in the HttpParser.CACHE + keep the MimeType.Type associated with the pre encoded Content-Type fields
1 parent 8c25183 commit 3d7f5da

File tree

6 files changed

+21
-15
lines changed

6 files changed

+21
-15
lines changed

jetty-core/jetty-client/src/test/java/org/eclipse/jetty/client/ContentResponseTest.java

+4-2
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,11 @@
2323
import org.eclipse.jetty.server.Request;
2424
import org.eclipse.jetty.server.Response;
2525
import org.eclipse.jetty.util.Callback;
26+
import org.hamcrest.Matchers;
2627
import org.junit.jupiter.params.ParameterizedTest;
2728
import org.junit.jupiter.params.provider.ArgumentsSource;
2829

30+
import static org.hamcrest.MatcherAssert.assertThat;
2931
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
3032
import static org.junit.jupiter.api.Assertions.assertEquals;
3133
import static org.junit.jupiter.api.Assertions.assertNull;
@@ -114,7 +116,7 @@ public boolean handle(Request request, Response response, Callback callback) thr
114116
assertEquals(200, response.getStatus());
115117
assertEquals(content, response.getContentAsString());
116118
assertEquals(mediaType, response.getMediaType());
117-
assertEquals(encoding, response.getEncoding());
119+
assertThat(response.getEncoding(), Matchers.equalToIgnoringCase(encoding));
118120
}
119121

120122
@ParameterizedTest
@@ -144,6 +146,6 @@ public boolean handle(Request request, Response response, Callback callback) thr
144146
assertEquals(200, response.getStatus());
145147
assertEquals(content, response.getContentAsString());
146148
assertEquals(mediaType, response.getMediaType());
147-
assertEquals(encoding, response.getEncoding());
149+
assertThat(response.getEncoding(), Matchers.equalToIgnoringCase(encoding));
148150
}
149151
}

jetty-core/jetty-client/src/test/java/org/eclipse/jetty/client/util/TypedContentProviderTest.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import org.eclipse.jetty.server.Request;
3030
import org.eclipse.jetty.server.Response;
3131
import org.eclipse.jetty.util.Fields;
32+
import org.hamcrest.Matchers;
3233
import org.junit.jupiter.params.ParameterizedTest;
3334
import org.junit.jupiter.params.provider.ArgumentsSource;
3435

@@ -96,7 +97,7 @@ public void testFormContentProviderWithDifferentContentType(Scenario scenario) t
9697
protected void service(Request request, Response response) throws Throwable
9798
{
9899
assertEquals("POST", request.getMethod());
99-
assertEquals(contentType, request.getHeaders().get(HttpHeader.CONTENT_TYPE));
100+
assertThat(request.getHeaders().get(HttpHeader.CONTENT_TYPE), Matchers.equalToIgnoringCase(contentType));
100101
assertEquals(content, Content.Source.asString(request));
101102
}
102103
});

jetty-ee10/jetty-ee10-tests/jetty-ee10-test-integration/src/test/java/org/eclipse/jetty/ee10/test/HttpInputTransientErrorTest.java

+4-3
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
import static org.hamcrest.MatcherAssert.assertThat;
4747
import static org.hamcrest.Matchers.contains;
4848
import static org.hamcrest.Matchers.containsString;
49+
import static org.hamcrest.Matchers.equalToIgnoringCase;
4950
import static org.hamcrest.Matchers.is;
5051
import static org.hamcrest.Matchers.nullValue;
5152
import static org.junit.jupiter.api.Assertions.assertInstanceOf;
@@ -181,7 +182,7 @@ public void onError(Throwable t)
181182

182183
assertThat("Unexpected response status\n" + response + response.getContent(), response.getStatus(), is(HttpStatus.OK_200));
183184
assertThat(response.get(HttpHeader.CONNECTION), nullValue());
184-
assertThat(response.get(HttpHeader.CONTENT_TYPE), is("text/plain;charset=UTF-8"));
185+
assertThat(response.get(HttpHeader.CONTENT_TYPE), equalToIgnoringCase("text/plain;charset=utf-8"));
185186
assertThat(response.getContent(), containsString("read=10"));
186187
assertInstanceOf(TimeoutException.class, failure.get());
187188
assertThat(events, contains("onError", "onAllDataRead"));
@@ -273,7 +274,7 @@ public void onError(Throwable t)
273274
HttpTester.Response response = HttpTester.parseResponse(localEndPoint.getResponse(false, 5, TimeUnit.SECONDS));
274275

275276
assertThat("Unexpected response status\n" + response + response.getContent(), response.getStatus(), is(HttpStatus.OK_200));
276-
assertThat(response.get(HttpHeader.CONTENT_TYPE), is("text/plain;charset=UTF-8"));
277+
assertThat(response.get(HttpHeader.CONTENT_TYPE), equalToIgnoringCase("text/plain;charset=utf-8"));
277278
assertThat(response.getContent(), containsString("read=10"));
278279
assertThat(failure.get(), nullValue());
279280
}
@@ -382,7 +383,7 @@ protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws I
382383
HttpTester.Response response = HttpTester.parseResponse(localEndPoint.getResponse(false, 5, TimeUnit.SECONDS));
383384

384385
assertThat("Unexpected response status\n" + response + response.getContent(), response.getStatus(), is(HttpStatus.OK_200));
385-
assertThat(response.get(HttpHeader.CONTENT_TYPE), is("text/plain;charset=UTF-8"));
386+
assertThat(response.get(HttpHeader.CONTENT_TYPE), equalToIgnoringCase("text/plain;charset=utf-8"));
386387
assertThat(response.getContent(), containsString("read=10"));
387388
assertInstanceOf(IOException.class, failure.get());
388389
assertInstanceOf(TimeoutException.class, failure.get().getCause());

jetty-ee11/jetty-ee11-servlet/src/test/java/org/eclipse/jetty/ee11/servlet/ResponseTest.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
import static org.hamcrest.MatcherAssert.assertThat;
4848
import static org.hamcrest.Matchers.containsString;
4949
import static org.hamcrest.Matchers.emptyString;
50+
import static org.hamcrest.Matchers.equalToIgnoringCase;
5051
import static org.hamcrest.Matchers.is;
5152
import static org.hamcrest.Matchers.not;
5253
import static org.hamcrest.Matchers.notNullValue;
@@ -140,7 +141,7 @@ protected void doGet(HttpServletRequest request, HttpServletResponse response) t
140141
HttpTester.Response response = HttpTester.parseResponse(responseBuffer);
141142

142143
assertThat(response.getStatus(), is(410));
143-
assertThat(response.get("Content-Type"), is("text/html;charset=ISO-8859-1"));
144+
assertThat(response.get("Content-Type"), equalToIgnoringCase("text/html;charset=iso-8859-1"));
144145
assertThat(response.getContent(), containsString("The content is gone."));
145146
}
146147

jetty-ee11/jetty-ee11-tests/jetty-ee11-test-integration/src/test/java/org/eclipse/jetty/ee11/test/HttpInputTransientErrorTest.java

+8-7
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
import static org.hamcrest.MatcherAssert.assertThat;
4646
import static org.hamcrest.Matchers.contains;
4747
import static org.hamcrest.Matchers.containsString;
48+
import static org.hamcrest.Matchers.equalToIgnoringCase;
4849
import static org.hamcrest.Matchers.is;
4950
import static org.hamcrest.Matchers.nullValue;
5051
import static org.junit.jupiter.api.Assertions.assertInstanceOf;
@@ -101,7 +102,7 @@ protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws I
101102
{
102103
AsyncContext asyncContext = req.startAsync(req, resp);
103104
asyncContext.setTimeout(0);
104-
resp.setContentType("text/plain;charset=UTF-8");
105+
resp.setContentType("text/plain;charset=utf-8");
105106

106107
// Since the client sends a request with a content-length header, but sends
107108
// the content only after idle timeout expired, this ReadListener will have
@@ -132,7 +133,7 @@ public void onAllDataRead() throws IOException
132133
{
133134
events.add("onAllDataRead");
134135
resp.setStatus(HttpStatus.OK_200);
135-
resp.setContentType("text/plain;charset=UTF-8");
136+
resp.setContentType("text/plain;charset=utf-8");
136137
resp.getWriter().println("read=" + counter.get());
137138
asyncContext.complete();
138139
}
@@ -180,7 +181,7 @@ public void onError(Throwable t)
180181

181182
assertThat("Unexpected response status\n" + response + response.getContent(), response.getStatus(), is(HttpStatus.OK_200));
182183
assertThat(response.get(HttpHeader.CONNECTION), nullValue());
183-
assertThat(response.get(HttpHeader.CONTENT_TYPE), is("text/plain;charset=UTF-8"));
184+
assertThat(response.get(HttpHeader.CONTENT_TYPE), equalToIgnoringCase("text/plain;charset=utf-8"));
184185
assertThat(response.getContent(), containsString("read=10"));
185186
assertInstanceOf(TimeoutException.class, failure.get());
186187
assertThat(events, contains("onError", "onAllDataRead"));
@@ -200,7 +201,7 @@ protected void doPost(HttpServletRequest req, HttpServletResponse resp)
200201
{
201202
AsyncContext asyncContext = req.startAsync(req, resp);
202203
asyncContext.setTimeout(0);
203-
resp.setContentType("text/plain;charset=UTF-8");
204+
resp.setContentType("text/plain;charset=utf-8");
204205

205206
// Not calling setReadListener will make Jetty set the ServletChannelState
206207
// in state WAITING upon doPost return, so idle timeouts are ignored.
@@ -272,7 +273,7 @@ public void onError(Throwable t)
272273
HttpTester.Response response = HttpTester.parseResponse(localEndPoint.getResponse(false, 5, TimeUnit.SECONDS));
273274

274275
assertThat("Unexpected response status\n" + response + response.getContent(), response.getStatus(), is(HttpStatus.OK_200));
275-
assertThat(response.get(HttpHeader.CONTENT_TYPE), is("text/plain;charset=UTF-8"));
276+
assertThat(response.get(HttpHeader.CONTENT_TYPE), equalToIgnoringCase("text/plain;charset=utf-8"));
276277
assertThat(response.getContent(), containsString("read=10"));
277278
assertThat(failure.get(), nullValue());
278279
}
@@ -362,7 +363,7 @@ protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws I
362363

363364
String content = IO.toString(req.getInputStream());
364365
resp.setStatus(HttpStatus.OK_200);
365-
resp.setContentType("text/plain;charset=UTF-8");
366+
resp.setContentType("text/plain;charset=utf-8");
366367
resp.getWriter().println("read=" + content.length());
367368
}
368369
});
@@ -381,7 +382,7 @@ protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws I
381382
HttpTester.Response response = HttpTester.parseResponse(localEndPoint.getResponse(false, 5, TimeUnit.SECONDS));
382383

383384
assertThat("Unexpected response status\n" + response + response.getContent(), response.getStatus(), is(HttpStatus.OK_200));
384-
assertThat(response.get(HttpHeader.CONTENT_TYPE), is("text/plain;charset=UTF-8"));
385+
assertThat(response.get(HttpHeader.CONTENT_TYPE), equalToIgnoringCase("text/plain;charset=utf-8"));
385386
assertThat(response.getContent(), containsString("read=10"));
386387
assertInstanceOf(IOException.class, failure.get());
387388
assertInstanceOf(TimeoutException.class, failure.get().getCause());

jetty-ee9/jetty-ee9-tests/jetty-ee9-test-integration/src/test/java/org/eclipse/jetty/ee9/test/HttpInputTransientErrorTest.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws I
9494
{
9595
AsyncContext asyncContext = req.startAsync(req, resp);
9696
asyncContext.setTimeout(0);
97-
resp.setContentType("text/plain;charset=UTF-8");
97+
resp.setContentType("text/plain;charset=utf-8");
9898

9999
req.getInputStream().setReadListener(new ReadListener()
100100
{

0 commit comments

Comments
 (0)