| 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 dart.io; |
| 6 | 6 |
| 7 | 7 |
| 8 /** | 8 /** |
| 9 * [HttpBodyHandler] is a helper class for parsing and collecting HTTP message | 9 * [HttpBodyHandler] is a helper class for parsing and collecting HTTP message |
| 10 * data in an easy-to-use [HttpBody] object. The content body is parsed, | 10 * data in an easy-to-use [HttpBody] object. The content body is parsed, |
| (...skipping 23 matching lines...) Expand all Loading... |
| 34 * The following mime-types will be handled specially: | 34 * The following mime-types will be handled specially: |
| 35 * - text/\* | 35 * - text/\* |
| 36 * - application/json | 36 * - application/json |
| 37 * | 37 * |
| 38 * All other mime-types will be returned as [List<int>]. | 38 * All other mime-types will be returned as [List<int>]. |
| 39 */ | 39 */ |
| 40 class HttpBodyHandler | 40 class HttpBodyHandler |
| 41 implements StreamTransformer<HttpRequest, HttpRequestBody> { | 41 implements StreamTransformer<HttpRequest, HttpRequestBody> { |
| 42 var _transformer; | 42 var _transformer; |
| 43 | 43 |
| 44 HttpBodyHandler() : _transformer = new _HttpBodyHandlerTransformer(); | 44 /** |
| 45 * Create a new [HttpBodyHandler] to be used with a [Stream]<[HttpRequest]>, |
| 46 * e.g. a [HttpServer]. |
| 47 * |
| 48 * If the page was served using different encoding than UTF-8, set |
| 49 * [defaultEncoding] accordingly. This is required for parsing |
| 50 * 'application/x-www-form-urlencoded' content correctly. |
| 51 */ |
| 52 HttpBodyHandler({Encoding defaultEncoding: Encoding.UTF_8}) |
| 53 : _transformer = new _HttpBodyHandlerTransformer(defaultEncoding); |
| 45 | 54 |
| 46 /** | 55 /** |
| 47 * Process and parse an incoming [HttpRequest]. The returned [HttpRequestBody] | 56 * Process and parse an incoming [HttpRequest]. The returned [HttpRequestBody] |
| 48 * contains a [response] field for accessing the [HttpResponse]. | 57 * contains a [response] field for accessing the [HttpResponse]. |
| 58 * |
| 59 * See [HttpBodyHandler] constructor for more info on [defaultEncoding]. |
| 49 */ | 60 */ |
| 50 static Future<HttpRequestBody> processRequest(HttpRequest request) { | 61 static Future<HttpRequestBody> processRequest( |
| 51 return _HttpBodyHandler.processRequest(request); | 62 HttpRequest request, |
| 63 {Encoding defaultEncoding: Encoding.UTF_8}) { |
| 64 return _HttpBodyHandler.processRequest(request, defaultEncoding); |
| 52 } | 65 } |
| 53 | 66 |
| 54 /** | 67 /** |
| 55 * Process and parse an incoming [HttpClientResponse]. | 68 * Process and parse an incoming [HttpClientResponse]. |
| 69 * |
| 70 * See [HttpBodyHandler] constructor for more info on [defaultEncoding]. |
| 56 */ | 71 */ |
| 57 static Future<HttpClientResponseBody> processResponse( | 72 static Future<HttpClientResponseBody> processResponse( |
| 58 HttpClientResponse response) { | 73 HttpClientResponse response, |
| 59 return _HttpBodyHandler.processResponse(response); | 74 {Encoding defaultEncoding: Encoding.UTF_8}) { |
| 75 return _HttpBodyHandler.processResponse(response, defaultEncoding); |
| 60 } | 76 } |
| 61 | 77 |
| 62 Stream<HttpRequestBody> bind(Stream<HttpRequest> stream) { | 78 Stream<HttpRequestBody> bind(Stream<HttpRequest> stream) { |
| 63 return _transformer.bind(stream); | 79 return _transformer.bind(stream); |
| 64 } | 80 } |
| 65 } | 81 } |
| 66 | 82 |
| 67 | 83 |
| 68 /** | 84 /** |
| 69 * A HTTP content body produced by [HttpBodyHandler] for either [HttpRequest] | 85 * A HTTP content body produced by [HttpBodyHandler] for either [HttpRequest] |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 159 * The [ContentType] of the uploaded file. For 'text/\*' and | 175 * The [ContentType] of the uploaded file. For 'text/\*' and |
| 160 * 'application/json' the [data] field will a String. | 176 * 'application/json' the [data] field will a String. |
| 161 */ | 177 */ |
| 162 ContentType contentType; | 178 ContentType contentType; |
| 163 | 179 |
| 164 /** | 180 /** |
| 165 * The content of the file. Either a [String] or a [List<int>]. | 181 * The content of the file. Either a [String] or a [List<int>]. |
| 166 */ | 182 */ |
| 167 dynamic content; | 183 dynamic content; |
| 168 } | 184 } |
| OLD | NEW |