diff --git a/test-jetty-servlet/src/main/java/org/eclipse/jetty/testing/HttpTester.java b/test-jetty-servlet/src/main/java/org/eclipse/jetty/testing/HttpTester.java index 46e31be676b..b49a807e3a3 100644 --- a/test-jetty-servlet/src/main/java/org/eclipse/jetty/testing/HttpTester.java +++ b/test-jetty-servlet/src/main/java/org/eclipse/jetty/testing/HttpTester.java @@ -444,7 +444,19 @@ public class HttpTester */ public void setHeader(String name, String value) { + if (HttpHeaders.CONTENT_TYPE.equalsIgnoreCase(name)) + setContentType(value); + else _fields.put(name,value); + + } + + /* ------------------------------------------------------------ */ + public void setContentType(String value) + { + _contentType = MimeTypes.CACHE.lookup(value); + _charset = MimeTypes.getCharsetFromContentType(_contentType); + _fields.put(HttpHeaders.CONTENT_TYPE_BUFFER,_contentType); } /* ------------------------------------------------------------ */ diff --git a/test-jetty-servlet/src/test/java/org/eclipse/jetty/testing/HttpTesterTest.java b/test-jetty-servlet/src/test/java/org/eclipse/jetty/testing/HttpTesterTest.java index b12ea713cce..60a9eb148e4 100644 --- a/test-jetty-servlet/src/test/java/org/eclipse/jetty/testing/HttpTesterTest.java +++ b/test-jetty-servlet/src/test/java/org/eclipse/jetty/testing/HttpTesterTest.java @@ -50,7 +50,25 @@ public class HttpTesterTest extends TestCase assertEquals(200, tester.getStatus()); assertEquals("22", tester.getHeader("Content-Length")); assertEquals("text/html",tester.getContentType()); - System.err.println(tester.getContent()); } + public void testSetCharset() throws Exception + { + String content = "123456789\uA74A"; + HttpTester tester = new HttpTester(); + tester.setVersion("HTTP/1.0"); + tester.setMethod("POST"); + tester.setHeader("Content-type", "application/json; charset=iso-8859-1"); + tester.setURI("/1/batch"); + tester.setContent(content); + assertEquals("123456789?",tester.getContent()); + + tester.setHeader("Content-type", "application/json; charset=UTF-8"); + tester.setContent(content); + assertEquals("123456789\uA74A",tester.getContent()); + + String request=tester.generate(); + assertTrue(request.startsWith("POST ")); + assertTrue(request.trim().endsWith(content)); + } }