OLD | NEW |
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 http_server; | 5 part of http_server; |
6 | 6 |
7 class _HttpBodyHandlerTransformer | 7 class _HttpBodyHandlerTransformer |
8 extends StreamEventTransformer<HttpRequest, HttpRequestBody> { | 8 extends StreamEventTransformer<HttpRequest, HttpRequestBody> { |
9 final Encoding _defaultEncoding; | 9 final Encoding _defaultEncoding; |
10 _HttpBodyHandlerTransformer(this._defaultEncoding); | 10 _HttpBodyHandlerTransformer(this._defaultEncoding); |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
60 .fold(new StringBuffer(), (buffer, data) => buffer..write(data)) | 60 .fold(new StringBuffer(), (buffer, data) => buffer..write(data)) |
61 .then((buffer) => new _HttpBody(contentType, | 61 .then((buffer) => new _HttpBody(contentType, |
62 "text", | 62 "text", |
63 buffer.toString())); | 63 buffer.toString())); |
64 } | 64 } |
65 | 65 |
66 Future<HttpBody> asFormData() { | 66 Future<HttpBody> asFormData() { |
67 return stream | 67 return stream |
68 .transform(new MimeMultipartTransformer( | 68 .transform(new MimeMultipartTransformer( |
69 contentType.parameters['boundary'])) | 69 contentType.parameters['boundary'])) |
70 .map((HttpMultipartFormData.parse)) | 70 .map((part) => HttpMultipartFormData.parse( |
| 71 part, defaultEncoding: defaultEncoding)) |
71 .map((multipart) { | 72 .map((multipart) { |
72 var future; | 73 var future; |
73 if (multipart.isText) { | 74 if (multipart.isText) { |
74 future = multipart | 75 future = multipart |
75 .fold(new StringBuffer(), (b, s) => b..write(s)) | 76 .fold(new StringBuffer(), (b, s) => b..write(s)) |
76 .then((b) => b.toString()); | 77 .then((b) => b.toString()); |
77 } else { | 78 } else { |
78 future = multipart | 79 future = multipart |
79 .fold(new BytesBuilder(), (b, d) => b..add(d)) | 80 .fold(new BytesBuilder(), (b, d) => b..add(d)) |
80 .then((b) => b.takeBytes()); | 81 .then((b) => b.takeBytes()); |
(...skipping 19 matching lines...) Expand all Loading... |
100 return new _HttpBody(contentType, 'form', map); | 101 return new _HttpBody(contentType, 'form', map); |
101 }); | 102 }); |
102 } | 103 } |
103 | 104 |
104 if (contentType == null) { | 105 if (contentType == null) { |
105 return asBinary(); | 106 return asBinary(); |
106 } | 107 } |
107 | 108 |
108 switch (contentType.primaryType) { | 109 switch (contentType.primaryType) { |
109 case "text": | 110 case "text": |
110 return asText(ASCII); | 111 return asText(defaultEncoding); |
111 | 112 |
112 case "application": | 113 case "application": |
113 switch (contentType.subType) { | 114 switch (contentType.subType) { |
114 case "json": | 115 case "json": |
115 return asText(UTF8) | 116 return asText(UTF8) |
116 .then((body) => new _HttpBody(contentType, | 117 .then((body) => new _HttpBody(contentType, |
117 "json", | 118 "json", |
118 JSON.decode(body.body))); | 119 JSON.decode(body.body))); |
119 | 120 |
120 case "x-www-form-urlencoded": | 121 case "x-www-form-urlencoded": |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
190 _HttpClientResponseBody(HttpClientResponse response, HttpBody body) | 191 _HttpClientResponseBody(HttpClientResponse response, HttpBody body) |
191 : super(body.contentType, body.type, body.body), | 192 : super(body.contentType, body.type, body.body), |
192 this.response = response; | 193 this.response = response; |
193 | 194 |
194 int get statusCode => response.statusCode; | 195 int get statusCode => response.statusCode; |
195 | 196 |
196 String get reasonPhrase => response.reasonPhrase; | 197 String get reasonPhrase => response.reasonPhrase; |
197 | 198 |
198 HttpHeaders get headers => response.headers; | 199 HttpHeaders get headers => response.headers; |
199 } | 200 } |
OLD | NEW |