45
45
import org .junit .Test ;
46
46
47
47
import org .apache .catalina .Context ;
48
+ import org .apache .catalina .Globals ;
48
49
import org .apache .catalina .authenticator .BasicAuthenticator ;
49
50
import org .apache .catalina .filters .FailedRequestFilter ;
50
51
import org .apache .catalina .startup .SimpleHttpClient ;
54
55
import org .apache .tomcat .unittest .TesterRequest ;
55
56
import org .apache .tomcat .util .buf .ByteChunk ;
56
57
import org .apache .tomcat .util .buf .EncodedSolidusHandling ;
58
+ import org .apache .tomcat .util .buf .StringUtils ;
57
59
import org .apache .tomcat .util .descriptor .web .FilterDef ;
58
60
import org .apache .tomcat .util .descriptor .web .FilterMap ;
59
61
import org .apache .tomcat .util .descriptor .web .LoginConfig ;
@@ -208,7 +210,7 @@ private Exception doRequest(int postLimit, boolean ucChunkedHead) {
208
210
request [0 ] =
209
211
"POST http://localhost:8080/test HTTP/1.1" + CRLF +
210
212
"Host: localhost:8080" + CRLF +
211
- "content-type: application/x-www-form-urlencoded" + CRLF +
213
+ SimpleHttpClient . HTTP_HEADER_CONTENT_TYPE_FORM_URL_ENCODING +
212
214
"Transfer-Encoding: CHUNKED" + CRLF +
213
215
"Connection: close" + CRLF +
214
216
CRLF +
@@ -218,7 +220,7 @@ private Exception doRequest(int postLimit, boolean ucChunkedHead) {
218
220
request [0 ] =
219
221
"POST http://localhost:8080/test HTTP/1.1" + CRLF +
220
222
"Host: localhost:8080" + CRLF +
221
- "content-type: application/x-www-form-urlencoded" + CRLF +
223
+ SimpleHttpClient . HTTP_HEADER_CONTENT_TYPE_FORM_URL_ENCODING +
222
224
"Transfer-Encoding: chunked" + CRLF +
223
225
"Connection: close" + CRLF +
224
226
CRLF +
@@ -420,7 +422,7 @@ public void testBug48692() {
420
422
// Make sure POST works properly
421
423
//
422
424
// POST with separate GET and POST parameters
423
- client .doRequest ("POST" , "foo=bar" , "application/x-www-form-urlencoded" , "bar=baz" , true );
425
+ client .doRequest ("POST" , "foo=bar" , Globals . CONTENT_TYPE_FORM_URL_ENCODING , "bar=baz" , true );
424
426
425
427
Assert .assertTrue ("Non-200 response for POST request" ,
426
428
client .isResponse200 ());
@@ -431,7 +433,7 @@ public void testBug48692() {
431
433
client .reset ();
432
434
433
435
// POST with overlapping GET and POST parameters
434
- client .doRequest ("POST" , "foo=bar&bar=foo" , "application/x-www-form-urlencoded" , "bar=baz&foo=baz" , true );
436
+ client .doRequest ("POST" , "foo=bar&bar=foo" , Globals . CONTENT_TYPE_FORM_URL_ENCODING , "bar=baz&foo=baz" , true );
435
437
436
438
Assert .assertTrue ("Non-200 response for POST request" ,
437
439
client .isResponse200 ());
@@ -442,7 +444,7 @@ public void testBug48692() {
442
444
client .reset ();
443
445
444
446
// PUT without POST-style parsing
445
- client .doRequest ("PUT" , "foo=bar&bar=foo" , "application/x-www-form-urlencoded" , "bar=baz&foo=baz" , false );
447
+ client .doRequest ("PUT" , "foo=bar&bar=foo" , Globals . CONTENT_TYPE_FORM_URL_ENCODING , "bar=baz&foo=baz" , false );
446
448
447
449
Assert .assertTrue ("Non-200 response for PUT/noparse request" ,
448
450
client .isResponse200 ());
@@ -453,7 +455,7 @@ public void testBug48692() {
453
455
client .reset ();
454
456
455
457
// PUT with POST-style parsing
456
- client .doRequest ("PUT" , "foo=bar&bar=foo" , "application/x-www-form-urlencoded" , "bar=baz&foo=baz" , true );
458
+ client .doRequest ("PUT" , "foo=bar&bar=foo" , Globals . CONTENT_TYPE_FORM_URL_ENCODING , "bar=baz&foo=baz" , true );
457
459
458
460
Assert .assertTrue ("Non-200 response for PUT request" ,
459
461
client .isResponse200 ());
@@ -462,14 +464,6 @@ public void testBug48692() {
462
464
client .getResponseBody ());
463
465
464
466
client .reset ();
465
-
466
- /*
467
- private Exception doRequest(String method,
468
- String queryString,
469
- String contentType,
470
- String requestBody,
471
- boolean allowBody) {
472
- */
473
467
}
474
468
475
469
@ Test
@@ -963,4 +957,64 @@ protected void doPost(HttpServletRequest req, HttpServletResponse resp)
963
957
req .getReader ();
964
958
}
965
959
}
960
+
961
+
962
+ /*
963
+ * https://bz.apache.org/bugzilla/show_bug.cgi?id=69442
964
+ */
965
+ @ Test
966
+ public void testTestParameterMediaTypeLowerCase () throws Exception {
967
+ // toLowerCase() is unnecessary but keep it in case the constant is changed in the future
968
+ doTestParameterMediaTypeCase (Globals .CONTENT_TYPE_FORM_URL_ENCODING .toLowerCase (Locale .ENGLISH ));
969
+ }
970
+
971
+
972
+ /*
973
+ * https://bz.apache.org/bugzilla/show_bug.cgi?id=69442
974
+ */
975
+ @ Test
976
+ public void testTestParameterMediaTypeUpperCase () throws Exception {
977
+ doTestParameterMediaTypeCase (Globals .CONTENT_TYPE_FORM_URL_ENCODING .toUpperCase (Locale .ENGLISH ));
978
+ }
979
+
980
+
981
+ private void doTestParameterMediaTypeCase (String contentType ) throws Exception {
982
+ // Setup Tomcat instance
983
+ Tomcat tomcat = getTomcatInstance ();
984
+
985
+ // No file system docBase required
986
+ Context ctx = getProgrammaticRootContext ();
987
+
988
+ Tomcat .addServlet (ctx , "servlet" , new Bug69442Servlet ());
989
+ ctx .addServletMappingDecoded ("/" , "servlet" );
990
+
991
+ tomcat .start ();
992
+
993
+ ByteChunk bc = new ByteChunk ();
994
+ Map <String ,List <String >> reqHeaders = new HashMap <>();
995
+ reqHeaders .put ("Content-Type" , Arrays .asList (contentType ));
996
+ postUrl ("a=b&c=d" .getBytes (), "http://localhost:" + getPort () + "/" , bc , reqHeaders , null );
997
+ String responseBody = bc .toString ();
998
+ Assert .assertTrue (responseBody , responseBody .contains ("a=b" ));
999
+ Assert .assertTrue (responseBody , responseBody .contains ("c=d" ));
1000
+ }
1001
+
1002
+
1003
+ private static class Bug69442Servlet extends HttpServlet {
1004
+
1005
+ private static final long serialVersionUID = 1L ;
1006
+
1007
+ @ Override
1008
+ protected void doPost (HttpServletRequest req , HttpServletResponse resp ) throws ServletException , IOException {
1009
+ resp .setContentType ("text/plain" );
1010
+ resp .setCharacterEncoding (StandardCharsets .UTF_8 .name ());
1011
+ PrintWriter pw = resp .getWriter ();
1012
+ Enumeration <String > names = req .getParameterNames ();
1013
+ while (names .hasMoreElements ()) {
1014
+ String name = names .nextElement ();
1015
+ String [] values = req .getParameterValues (name );
1016
+ pw .println (name + "=" + StringUtils .join (values ));
1017
+ }
1018
+ }
1019
+ }
966
1020
}
0 commit comments