| 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 21 matching lines...) Expand all Loading... |
| 32 * }); | 32 * }); |
| 33 * | 33 * |
| 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 factory HttpBodyHandler() => new _HttpBodyHandler(); | 42 var _transformer; |
| 43 |
| 44 HttpBodyHandler() : _transformer = new _HttpBodyHandlerTransformer(); |
| 43 | 45 |
| 44 /** | 46 /** |
| 45 * Process and parse an incoming [HttpRequest]. The returned [HttpRequestBody] | 47 * Process and parse an incoming [HttpRequest]. The returned [HttpRequestBody] |
| 46 * contains a [response] field for accessing the [HttpResponse]. | 48 * contains a [response] field for accessing the [HttpResponse]. |
| 47 */ | 49 */ |
| 48 static Future<HttpRequestBody> processRequest(HttpRequest request) { | 50 static Future<HttpRequestBody> processRequest(HttpRequest request) { |
| 49 return _HttpBodyHandler.processRequest(request); | 51 return _HttpBodyHandler.processRequest(request); |
| 50 } | 52 } |
| 51 | 53 |
| 52 /** | 54 /** |
| 53 * Process and parse an incoming [HttpClientResponse]. | 55 * Process and parse an incoming [HttpClientResponse]. |
| 54 */ | 56 */ |
| 55 static Future<HttpClientResponseBody> processResponse( | 57 static Future<HttpClientResponseBody> processResponse( |
| 56 HttpClientResponse response) { | 58 HttpClientResponse response) { |
| 57 return _HttpBodyHandler.processResponse(response); | 59 return _HttpBodyHandler.processResponse(response); |
| 58 } | 60 } |
| 61 |
| 62 Stream<HttpRequestBody> bind(Stream<HttpRequest> stream) { |
| 63 return _transformer.bind(stream); |
| 64 } |
| 59 } | 65 } |
| 60 | 66 |
| 61 | 67 |
| 62 /** | 68 /** |
| 63 * A HTTP content body produced by [HttpBodyHandler] for either [HttpRequest] | 69 * A HTTP content body produced by [HttpBodyHandler] for either [HttpRequest] |
| 64 * or [HttpClientResponse]. | 70 * or [HttpClientResponse]. |
| 65 */ | 71 */ |
| 66 abstract class HttpBody { | 72 abstract class HttpBody { |
| 67 /** | 73 /** |
| 68 * The content type e.g. application/json, application/octet-stream, | 74 * The content type e.g. application/json, application/octet-stream, |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 130 /** | 136 /** |
| 131 * Returns the request headers. | 137 * Returns the request headers. |
| 132 */ | 138 */ |
| 133 HttpHeaders get headers; | 139 HttpHeaders get headers; |
| 134 | 140 |
| 135 /** | 141 /** |
| 136 * The [HttpResponse] used for responding to the client. | 142 * The [HttpResponse] used for responding to the client. |
| 137 */ | 143 */ |
| 138 HttpResponse get response; | 144 HttpResponse get response; |
| 139 } | 145 } |
| OLD | NEW |