 Chromium Code Reviews
 Chromium Code Reviews Issue 10407002:
  Add special handling of the content type HTTP header  (Closed) 
  Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
    
  
    Issue 10407002:
  Add special handling of the content type HTTP header  (Closed) 
  Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart| Index: tests/standalone/io/http_test.dart | 
| diff --git a/tests/standalone/io/http_test.dart b/tests/standalone/io/http_test.dart | 
| index eab4b858265ca558e8a6a1ad46d4533e6648d1bf..487cc16b005719c59448d9ae3a298e557e8a5470 100644 | 
| --- a/tests/standalone/io/http_test.dart | 
| +++ b/tests/standalone/io/http_test.dart | 
| @@ -154,6 +154,27 @@ class TestServer extends Isolate { | 
| response.outputStream.close(); | 
| } | 
| + void _contentType1Handler(HttpRequest request, HttpResponse response) { | 
| + Expect.equals("text/html", request.headers.contentType.value); | 
| + Expect.equals("text", request.headers.contentType.primaryType); | 
| + Expect.equals("html", request.headers.contentType.subType); | 
| + Expect.equals("utf-8", request.headers.contentType.parameters["charset"]); | 
| + | 
| + response.headers.contentType.value = "text/html"; | 
| + response.headers.contentType.parameters["charset"] = "utf-8"; | 
| + response.outputStream.close(); | 
| + } | 
| + | 
| + void _contentType2Handler(HttpRequest request, HttpResponse response) { | 
| + Expect.equals("text/html", request.headers.contentType.value); | 
| + Expect.equals("text", request.headers.contentType.primaryType); | 
| + Expect.equals("html", request.headers.contentType.subType); | 
| + Expect.equals("utf-8", request.headers.contentType.parameters["charset"]); | 
| + | 
| + response.headers.set(HttpHeaders.CONTENT_TYPE, "text/html; charset = utf-8"); | 
| 
Mads Ager (google)
2012/05/21 07:40:39
Long line. Also multiple long lines below.
 
Søren Gjesse
2012/05/21 11:11:06
Done.
 | 
| + response.outputStream.close(); | 
| + } | 
| + | 
| void main() { | 
| // Setup request handlers. | 
| _requestHandlers = new Map(); | 
| @@ -180,6 +201,14 @@ class TestServer extends Isolate { | 
| (HttpRequest request, HttpResponse response) { | 
| _expires2Handler(request, response); | 
| }; | 
| + _requestHandlers["/contenttype1"] = | 
| + (HttpRequest request, HttpResponse response) { | 
| + _contentType1Handler(request, response); | 
| + }; | 
| + _requestHandlers["/contenttype2"] = | 
| + (HttpRequest request, HttpResponse response) { | 
| + _contentType2Handler(request, response); | 
| + }; | 
| this.port.receive((var message, SendPort replyTo) { | 
| if (message.isStart) { | 
| @@ -514,9 +543,51 @@ void testExpires() { | 
| testServerMain.start(); | 
| } | 
| +void testContentType() { | 
| + TestServerMain testServerMain = new TestServerMain(); | 
| + testServerMain.setServerStartedHandler((int port) { | 
| + int responses = 0; | 
| + HttpClient httpClient = new HttpClient(); | 
| + | 
| + void processResponse(HttpClientResponse response) { | 
| + Expect.equals(HttpStatus.OK, response.statusCode); | 
| + Expect.equals("text/html; charset=utf-8", | 
| + response.headers.contentType.toString()); | 
| + Expect.equals("text/html", response.headers.contentType.value); | 
| + Expect.equals("text", response.headers.contentType.primaryType); | 
| + Expect.equals("html", response.headers.contentType.subType); | 
| + Expect.equals("utf-8", response.headers.contentType.parameters["charset"]); | 
| + responses++; | 
| + if (responses == 2) { | 
| + httpClient.shutdown(); | 
| + testServerMain.shutdown(); | 
| + } | 
| + } | 
| + | 
| + HttpClientConnection conn1 = httpClient.get("127.0.0.1", port, "/contenttype1"); | 
| + conn1.onRequest = (HttpClientRequest request) { | 
| + request.headers.contentType.value = "text/html"; | 
| + request.headers.contentType.parameters["charset"] = "utf-8"; | 
| + request.outputStream.close(); | 
| + }; | 
| + conn1.onResponse = (HttpClientResponse response) { | 
| + processResponse(response); | 
| + }; | 
| + HttpClientConnection conn2 = httpClient.get("127.0.0.1", port, "/contenttype2"); | 
| + conn2.onRequest = (HttpClientRequest request) { | 
| + request.headers.set(HttpHeaders.CONTENT_TYPE, "text/html; charset = utf-8"); | 
| + request.outputStream.close(); | 
| + }; | 
| + conn2.onResponse = (HttpClientResponse response) { | 
| + processResponse(response); | 
| + }; | 
| + }); | 
| + testServerMain.start(); | 
| +} | 
| + | 
| void main() { | 
| - testStartStop(); | 
| + /*testStartStop(); | 
| 
Anders Johnsen
2012/05/21 07:37:30
We should still run every test ;)
 
Mads Ager (google)
2012/05/21 07:40:39
Code in comments.
 
Søren Gjesse
2012/05/21 11:11:06
Done.
 
Søren Gjesse
2012/05/21 11:11:06
Done.
 | 
| testGET(); | 
| testPOST(true); | 
| testPOST(false); | 
| @@ -527,5 +598,6 @@ void main() { | 
| test404(); | 
| testReasonPhrase(); | 
| testHost(); | 
| - testExpires(); | 
| + testExpires();*/ | 
| + testContentType(); | 
| } |