Chromium Code Reviews| 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 dart.io; | 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); |
| 11 | 11 |
| 12 void handleData(HttpRequest request, EventSink<HttpRequestBody> sink) { | 12 void handleData(HttpRequest request, EventSink<HttpRequestBody> sink) { |
| 13 _HttpBodyHandler.processRequest(request, _defaultEncoding) | 13 _HttpBodyHandler.processRequest(request, _defaultEncoding) |
| 14 .then(sink.add, onError: sink.addError); | 14 .then(sink.add, onError: sink.addError); |
| 15 } | 15 } |
| (...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 143 break; | 143 break; |
| 144 } | 144 } |
| 145 break; | 145 break; |
| 146 | 146 |
| 147 default: | 147 default: |
| 148 break; | 148 break; |
| 149 } | 149 } |
| 150 | 150 |
| 151 return asBinary(); | 151 return asBinary(); |
| 152 } | 152 } |
| 153 | |
| 154 // Utility function to synchronously decode a list of bytes. | |
| 155 static String _decodeString(List<int> bytes, | |
| 156 [Encoding encoding = Encoding.UTF_8]) { | |
| 157 if (bytes.length == 0) return ""; | |
| 158 var string; | |
| 159 var error; | |
| 160 var controller = new StreamController(sync: true); | |
| 161 controller.stream | |
| 162 .transform(new StringDecoder(encoding)) | |
| 163 .listen((data) => string = data, | |
|
Bill Hesse
2013/07/12 11:43:33
What about an input that ends in half of an encode
Anders Johnsen
2013/07/15 08:21:32
Yes, see line 166.
Bill Hesse
2013/07/15 08:26:33
OK, so controller.close is guaranteed to synchrono
| |
| 164 onError: (e) => error = e); | |
| 165 controller.add(bytes); | |
| 166 controller.close(); | |
| 167 if (error != null) throw error; | |
| 168 assert(string != null); | |
| 169 return string; | |
| 170 } | |
| 153 } | 171 } |
| 154 | 172 |
| 155 class _HttpBodyFileUpload implements HttpBodyFileUpload { | 173 class _HttpBodyFileUpload implements HttpBodyFileUpload { |
| 156 final ContentType contentType; | 174 final ContentType contentType; |
| 157 final String filename; | 175 final String filename; |
| 158 final dynamic content; | 176 final dynamic content; |
| 159 _HttpBodyFileUpload(this.contentType, this.filename, this.content); | 177 _HttpBodyFileUpload(this.contentType, this.filename, this.content); |
| 160 } | 178 } |
| 161 | 179 |
| 162 class _HttpBody implements HttpBody { | 180 class _HttpBody implements HttpBody { |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 190 _HttpClientResponseBody(HttpClientResponse response, HttpBody body) | 208 _HttpClientResponseBody(HttpClientResponse response, HttpBody body) |
| 191 : super(body.contentType, body.type, body.body), | 209 : super(body.contentType, body.type, body.body), |
| 192 this.response = response; | 210 this.response = response; |
| 193 | 211 |
| 194 int get statusCode => response.statusCode; | 212 int get statusCode => response.statusCode; |
| 195 | 213 |
| 196 String get reasonPhrase => response.reasonPhrase; | 214 String get reasonPhrase => response.reasonPhrase; |
| 197 | 215 |
| 198 HttpHeaders get headers => response.headers; | 216 HttpHeaders get headers => response.headers; |
| 199 } | 217 } |
| OLD | NEW |