Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(756)

Side by Side Diff: sdk/lib/io/http_body_impl.dart

Issue 14113006: Fix HttpBodyHandler to handle missing mimeType. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 part of dart.io; 5 part of dart.io;
6 6
7 class _HttpBodyHandlerTransformer 7 class _HttpBodyHandlerTransformer
8 extends StreamEventTransformer<HttpRequest, HttpRequestBody> { 8 extends StreamEventTransformer<HttpRequest, HttpRequestBody> {
9 void handleData(HttpRequest request, EventSink<HttpRequestBody> sink) { 9 void handleData(HttpRequest request, EventSink<HttpRequestBody> sink) {
10 HttpBodyHandler.processRequest(request) 10 HttpBodyHandler.processRequest(request)
(...skipping 29 matching lines...) Expand all
40 return stream.fold( 40 return stream.fold(
41 new _BufferList(), 41 new _BufferList(),
42 (buffer, data) { 42 (buffer, data) {
43 // TODO(ajohnsen): Add limit for POST data. 43 // TODO(ajohnsen): Add limit for POST data.
44 buffer.add(data); 44 buffer.add(data);
45 return buffer; 45 return buffer;
46 }) 46 })
47 .then((list) { 47 .then((list) {
48 dynamic content = list.readBytes(); 48 dynamic content = list.readBytes();
49 String type = "binary"; 49 String type = "binary";
50 String mimeType = headers.contentType.toString(); 50 ContentType contentType = headers.contentType;
51 if (contentType == null) {
52 return new _HttpBody(null, type, content);
53 }
54 String mimeType = "${contentType.primaryType}/${contentType.subType}";
Søren Gjesse 2013/04/15 11:11:28 Maybe add gettet type or value to class ContentTyp
Anders Johnsen 2013/04/15 11:19:26 Done.
51 String asText(Encoding defaultEncoding) { 55 String asText(Encoding defaultEncoding) {
52 var encoding; 56 var encoding;
53 var charset = headers.contentType.charset; 57 var charset = contentType.charset;
54 if (charset != null) encoding = Encoding.fromName(charset); 58 if (charset != null) encoding = Encoding.fromName(charset);
55 if (encoding == null) encoding = defaultEncoding; 59 if (encoding == null) encoding = defaultEncoding;
56 return _decodeString(content, encoding); 60 return _decodeString(content, encoding);
57 } 61 }
58 switch (headers.contentType.primaryType) { 62 switch (contentType.primaryType) {
59 case "text": 63 case "text":
60 type = "text"; 64 type = "text";
61 content = asText(Encoding.ASCII); 65 content = asText(Encoding.ASCII);
62 break; 66 break;
63 67
64 case "application": 68 case "application":
65 switch (headers.contentType.subType) { 69 switch (contentType.subType) {
66 case "json": 70 case "json":
67 content = JSON.parse(asText(Encoding.UTF_8)); 71 content = JSON.parse(asText(Encoding.UTF_8));
68 type = "json"; 72 type = "json";
69 break; 73 break;
70 74
71 default: 75 default:
72 break; 76 break;
73 } 77 }
74 break; 78 break;
75 79
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
110 final int statusCode; 114 final int statusCode;
111 final String reasonPhrase; 115 final String reasonPhrase;
112 final HttpHeaders headers; 116 final HttpHeaders headers;
113 117
114 _HttpClientResponseBody(HttpClientResponse response, HttpBody body) 118 _HttpClientResponseBody(HttpClientResponse response, HttpBody body)
115 : super(body.mimeType, body.type, body.body), 119 : super(body.mimeType, body.type, body.body),
116 statusCode = response.statusCode, 120 statusCode = response.statusCode,
117 reasonPhrase = response.reasonPhrase, 121 reasonPhrase = response.reasonPhrase,
118 headers = response.headers; 122 headers = response.headers;
119 } 123 }
OLDNEW
« no previous file with comments | « no previous file | tests/standalone/io/http_body_test.dart » ('j') | tests/standalone/io/http_body_test.dart » ('J')

Powered by Google App Engine
This is Rietveld 408576698