| 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 | 7 |
| 8 /** | 8 /** |
| 9 * [HttpBodyHandler] is a helper class for processing and collecting | 9 * [HttpBodyHandler] is a helper class for processing and collecting |
| 10 * HTTP message data in an easy-to-use [HttpBody] object. The content | 10 * HTTP message data in an easy-to-use [HttpBody] object. The content |
| 11 * body is parsed, depending on the `Content-Type` header field. When | 11 * body is parsed, depending on the `Content-Type` header field. When |
| 12 * the full body is read and parsed the body content is made | 12 * the full body is read and parsed the body content is made |
| 13 * available. The class can be used to process both server requests | 13 * available. The class can be used to process both server requests |
| 14 * and client responses. | 14 * and client responses. |
| 15 * | 15 * |
| 16 * The following content types are recognized: | 16 * The following content types are recognized: |
| 17 * | 17 * |
| 18 * text/\* | 18 * text/* |
| 19 * application/json | 19 * application/json |
| 20 * application/x-www-form-urlencoded | 20 * application/x-www-form-urlencoded |
| 21 * multipart/form-data | 21 * multipart/form-data |
| 22 * | 22 * |
| 23 * For content type `text/\*` the body is decoded into a string. The | 23 * For content type `text/\*` the body is decoded into a string. The |
| 24 * 'charset' parameter of the content type specifies the encoding | 24 * 'charset' parameter of the content type specifies the encoding |
| 25 * used for decoding. If no 'charset' is present the default encoding | 25 * used for decoding. If no 'charset' is present the default encoding |
| 26 * of ISO-8859-1 is used. | 26 * of ISO-8859-1 is used. |
| 27 * | 27 * |
| 28 * For content type `application/json` the body is decoded into a | 28 * For content type `application/json` the body is decoded into a |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 134 } | 134 } |
| 135 } | 135 } |
| 136 | 136 |
| 137 | 137 |
| 138 /** | 138 /** |
| 139 * A HTTP content body produced by [HttpBodyHandler] for either [HttpRequest] | 139 * A HTTP content body produced by [HttpBodyHandler] for either [HttpRequest] |
| 140 * or [HttpClientResponse]. | 140 * or [HttpClientResponse]. |
| 141 */ | 141 */ |
| 142 abstract class HttpBody { | 142 abstract class HttpBody { |
| 143 /** | 143 /** |
| 144 * The content type e.g. application/json, application/octet-stream, | |
| 145 * application/x-www-form-urlencoded, text/plain. | |
| 146 */ | |
| 147 ContentType get contentType; | |
| 148 | |
| 149 /** | |
| 150 * A high-level type value, that reflects how the body was parsed, e.g. | 144 * A high-level type value, that reflects how the body was parsed, e.g. |
| 151 * "text", "binary" and "json". | 145 * "text", "binary" and "json". |
| 152 */ | 146 */ |
| 153 String get type; | 147 String get type; |
| 154 | 148 |
| 155 /** | 149 /** |
| 156 * The actual body. The type depends on [type]. | 150 * The actual body. The type depends on [type]. |
| 157 */ | 151 */ |
| 158 dynamic get body; | 152 dynamic get body; |
| 159 } | 153 } |
| 160 | 154 |
| 161 | 155 |
| 162 /** | 156 /** |
| 163 * The [HttpBody] of a [HttpClientResponse] will be of type | 157 * The [HttpBody] of a [HttpClientResponse] will be of type |
| 164 * [HttpClientResponseBody]. It contains the [HttpClientResponse] object | 158 * [HttpClientResponseBody]. It contains the [HttpClientResponse] object |
| 165 * for access to the headers. | 159 * for access to the headers. |
| 166 */ | 160 */ |
| 167 abstract class HttpClientResponseBody extends HttpBody { | 161 abstract class HttpClientResponseBody extends HttpBody { |
| 168 /** | 162 /** |
| 169 * Returns the status code. | 163 * The [HttpClientResponse] from which the [HttpClientResponseBody] was |
| 170 */ | 164 * created. |
| 171 int get statusCode; | |
| 172 | |
| 173 /** | |
| 174 * Returns the reason phrase associated with the status code. | |
| 175 */ | |
| 176 String get reasonPhrase; | |
| 177 | |
| 178 /** | |
| 179 * Returns the response headers. | |
| 180 */ | |
| 181 HttpHeaders get headers; | |
| 182 | |
| 183 /** | |
| 184 * The [HttpClientResponse] of the HTTP body. | |
| 185 */ | 165 */ |
| 186 HttpClientResponse get response; | 166 HttpClientResponse get response; |
| 187 } | 167 } |
| 188 | 168 |
| 189 | 169 |
| 190 /** | 170 /** |
| 191 * The [HttpBody] of a [HttpRequest] will be of type [HttpRequestBody]. It | 171 * The [HttpBody] of a [HttpRequest] will be of type [HttpRequestBody]. It |
| 192 * contains the fields used to read all request header information and | 172 * provides access to the request, for reading all request header information |
| 193 * responding to the client. | 173 * and responding to the client. |
| 194 */ | 174 */ |
| 195 abstract class HttpRequestBody extends HttpBody { | 175 abstract class HttpRequestBody extends HttpBody { |
| 196 /** | 176 /** |
| 197 * Returns the method for the request. | 177 * The [HttpRequest] from which the [HttpRequestBody] was created. |
| 178 * |
| 179 * Note that the [HttpRequest] is already drained at this point, so the |
| 180 * `Stream` methods cannot be used. |
| 198 */ | 181 */ |
| 199 String get method; | 182 HttpRequest get request; |
| 200 | |
| 201 /** | |
| 202 * Returns the URI for the request. | |
| 203 */ | |
| 204 Uri get uri; | |
| 205 | |
| 206 /** | |
| 207 * Returns the request headers. | |
| 208 */ | |
| 209 HttpHeaders get headers; | |
| 210 | |
| 211 /** | |
| 212 * The [HttpResponse] used for responding to the client. | |
| 213 */ | |
| 214 HttpResponse get response; | |
| 215 } | 183 } |
| 216 | 184 |
| 217 | 185 |
| 218 /** | 186 /** |
| 219 * A [HttpBodyFileUpload] object wraps a file upload, presenting a way for | 187 * A [HttpBodyFileUpload] object wraps a file upload, presenting a way for |
| 220 * extracting filename, contentType and the data of the uploaded file. | 188 * extracting filename, contentType and the data of the uploaded file. |
| 221 */ | 189 */ |
| 222 abstract class HttpBodyFileUpload { | 190 abstract class HttpBodyFileUpload { |
| 223 /** | 191 /** |
| 224 * The filename of the uploaded file. | 192 * The filename of the uploaded file. |
| 225 */ | 193 */ |
| 226 String get filename; | 194 String get filename; |
| 227 | 195 |
| 228 /** | 196 /** |
| 229 * The [ContentType] of the uploaded file. For 'text/\*' and | 197 * The [ContentType] of the uploaded file. For 'text/\*' and |
| 230 * 'application/json' the [data] field will a String. | 198 * 'application/json' the [data] field will a String. |
| 231 */ | 199 */ |
| 232 ContentType get contentType; | 200 ContentType get contentType; |
| 233 | 201 |
| 234 /** | 202 /** |
| 235 * The content of the file. Either a [String] or a [List<int>]. | 203 * The content of the file. Either a [String] or a [List<int>]. |
| 236 */ | 204 */ |
| 237 dynamic get content; | 205 dynamic get content; |
| 238 } | 206 } |
| OLD | NEW |