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

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: fix comment. 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
« no previous file with comments | « sdk/lib/io/http.dart ('k') | sdk/lib/io/http_headers.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 }
51 String asText(Encoding defaultEncoding) { 54 String asText(Encoding defaultEncoding) {
52 var encoding; 55 var encoding;
53 var charset = headers.contentType.charset; 56 var charset = contentType.charset;
54 if (charset != null) encoding = Encoding.fromName(charset); 57 if (charset != null) encoding = Encoding.fromName(charset);
55 if (encoding == null) encoding = defaultEncoding; 58 if (encoding == null) encoding = defaultEncoding;
56 return _decodeString(content, encoding); 59 return _decodeString(content, encoding);
57 } 60 }
58 switch (headers.contentType.primaryType) { 61 switch (contentType.primaryType) {
59 case "text": 62 case "text":
60 type = "text"; 63 type = "text";
61 content = asText(Encoding.ASCII); 64 content = asText(Encoding.ASCII);
62 break; 65 break;
63 66
64 case "application": 67 case "application":
65 switch (headers.contentType.subType) { 68 switch (contentType.subType) {
66 case "json": 69 case "json":
67 content = JSON.parse(asText(Encoding.UTF_8)); 70 content = JSON.parse(asText(Encoding.UTF_8));
68 type = "json"; 71 type = "json";
69 break; 72 break;
70 73
71 default: 74 default:
72 break; 75 break;
73 } 76 }
74 break; 77 break;
75 78
76 default: 79 default:
77 break; 80 break;
78 } 81 }
79 return new _HttpBody(mimeType, type, content); 82 return new _HttpBody(contentType.mimeType, type, content);
80 }); 83 });
81 } 84 }
82 } 85 }
83 86
84 class _HttpBody implements HttpBody { 87 class _HttpBody implements HttpBody {
85 final String mimeType; 88 final String mimeType;
86 final String type; 89 final String type;
87 final dynamic body; 90 final dynamic body;
88 91
89 _HttpBody(String this.mimeType, 92 _HttpBody(String this.mimeType,
(...skipping 20 matching lines...) Expand all
110 final int statusCode; 113 final int statusCode;
111 final String reasonPhrase; 114 final String reasonPhrase;
112 final HttpHeaders headers; 115 final HttpHeaders headers;
113 116
114 _HttpClientResponseBody(HttpClientResponse response, HttpBody body) 117 _HttpClientResponseBody(HttpClientResponse response, HttpBody body)
115 : super(body.mimeType, body.type, body.body), 118 : super(body.mimeType, body.type, body.body),
116 statusCode = response.statusCode, 119 statusCode = response.statusCode,
117 reasonPhrase = response.reasonPhrase, 120 reasonPhrase = response.reasonPhrase,
118 headers = response.headers; 121 headers = response.headers;
119 } 122 }
OLDNEW
« no previous file with comments | « sdk/lib/io/http.dart ('k') | sdk/lib/io/http_headers.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698