Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // BSD-style license that can be found in the LICENSE file. | |
| 4 | |
| 5 part of dart.io; | |
| 6 | |
| 7 /** | |
| 8 * A helper-class for HTTP library, for parsing and collecting HTTP message | |
|
Mads Ager (google)
2013/04/10 08:20:26
Simplify to:
[HttpBodyHandler] is a helper class
Anders Johnsen
2013/04/10 12:52:49
Done.
| |
| 9 * data, in a easy-to-use [HttpBody] structure. | |
| 10 * | |
| 11 * To use with the [HttpServer] for request messages, [HttpBodyHandler] can be | |
| 12 * used as either a [StreamTransformer] or as a per-request handler (see | |
| 13 * [processRequest]). | |
|
Mads Ager (google)
2013/04/10 08:20:26
How about adding the actual code for the two appro
Anders Johnsen
2013/04/10 12:52:49
Done.
| |
| 14 * | |
| 15 * To use with the [HttpClient] for response messages, [HttpBodyHandler] can be | |
| 16 * used as a per-request handler (see [processResponse]). | |
| 17 * | |
| 18 * The content body is parsed, depending on the set 'Content-Type' header field. | |
|
Søren Gjesse
2013/04/10 07:09:11
Remove 'set'.
I think we should enumerate the mim
Mads Ager (google)
2013/04/10 08:20:26
How about integrating this sentence in the first p
Anders Johnsen
2013/04/10 12:52:49
Done.
| |
| 19 */ | |
| 20 class HttpBodyHandler | |
|
Søren Gjesse
2013/04/10 07:09:11
I like the transformer class with static methods f
Anders Johnsen
2013/04/10 12:52:49
As discussed offline, this will serve as a great a
| |
| 21 implements StreamTransformer<HttpRequest, HttpRequestBody> { | |
| 22 factory HttpBodyHandler() => new _HttpBodyHandler(); | |
| 23 | |
| 24 /** | |
| 25 * Process and parse an incoming [HttpRequest]. The returned [HttpRequestBody] | |
| 26 * contains a [response] field for accessing the [HttpResponse]. | |
| 27 */ | |
| 28 static Future<HttpRequestBody> processRequest(HttpRequest request) { | |
| 29 return _HttpBodyHandler.processRequest(request); | |
| 30 } | |
| 31 | |
| 32 /** | |
| 33 * Process and parse an incoming [HttpClientResponse]. | |
| 34 */ | |
| 35 static Future<HttpBody> processResponse(HttpClientResponse response) { | |
| 36 return _HttpBodyHandler.processResponse(response); | |
| 37 } | |
| 38 } | |
| 39 | |
| 40 /** | |
| 41 * A HTTP content body produced by [HttpBodyHandler] for either [HttpRequest] | |
| 42 * or [HttpClientResponse]. | |
| 43 */ | |
| 44 abstract class HttpBody { | |
| 45 static int BINARY = 0; | |
|
Mads Ager (google)
2013/04/10 08:20:26
Make this a real HttpBodyType type instead of an i
Anders Johnsen
2013/04/10 12:52:49
Done.
| |
| 46 static int TEXT = 1; | |
| 47 static int JSON = 2; | |
| 48 static int FORM = 3; | |
| 49 | |
| 50 /** | |
| 51 * The content type e.g. application/json, application/octet-stream, | |
| 52 * application/x-www-form-urlencoded, text/plain. | |
| 53 */ | |
| 54 String get mimeType; | |
| 55 | |
| 56 /** | |
| 57 * A high-level type value, that reflects how the body was parsed, e.g. | |
| 58 * [JSON], [BINARY], [FORM], [TEXT]. | |
| 59 */ | |
| 60 int get type; | |
|
Mads Ager (google)
2013/04/10 08:20:26
HttpBodyType get type;
?
Anders Johnsen
2013/04/10 12:52:49
Done.
| |
| 61 | |
| 62 /** | |
| 63 * The actual body. The type depends on [type] ([Map] for [JSON] and [FROM], | |
|
Søren Gjesse
2013/04/10 07:09:11
FROM -> FORM
Anders Johnsen
2013/04/10 12:52:49
Done.
| |
| 64 * [List<int>] for [BINARY] etc. | |
| 65 */ | |
| 66 dynamic get body; | |
| 67 | |
| 68 /** | |
| 69 * [Map] if [JSON], null otherwise. | |
|
Mads Ager (google)
2013/04/10 08:20:26
[Map] if [type] equals [JSON], null otherwise.
?
Anders Johnsen
2013/04/10 12:52:49
These are removed.
| |
| 70 */ | |
| 71 Map get json; | |
| 72 | |
| 73 /** | |
| 74 * [List<int>] if [BINARY], null otherwise. | |
| 75 */ | |
| 76 List<int> get binary; | |
| 77 | |
| 78 /** | |
| 79 * [Map] if [FORM], null otherwise. | |
| 80 */ | |
| 81 Map get form; | |
| 82 | |
| 83 /** | |
| 84 * [String] if [TEXT], null otherwise. | |
| 85 */ | |
| 86 String get text; | |
|
Søren Gjesse
2013/04/10 07:09:11
Should we add isBinary, isJson, etc. as well?
Anders Johnsen
2013/04/10 12:52:49
No (due to offline chat).
| |
| 87 } | |
| 88 | |
| 89 abstract class HttpRequestBody extends HttpBody { | |
|
Mads Ager (google)
2013/04/10 08:20:26
Add a top level comment for HttpRequestBody explai
Anders Johnsen
2013/04/10 12:52:49
Done.
| |
| 90 /** | |
| 91 * The [HttpResponse] used for responding to the client. | |
| 92 */ | |
| 93 HttpResponse get response; | |
| 94 } | |
| OLD | NEW |