| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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 #library("http"); | 5 #library("http"); |
| 6 #import("dart:io"); | 6 #import("dart:io"); |
| 7 #source("http_impl.dart"); | 7 #source("http_impl.dart"); |
| 8 #source("../../runtime/bin/buffer_list.dart"); |
| 9 #source("../../runtime/bin/stream_util.dart"); |
| 8 | 10 |
| 9 /** | 11 /** |
| 10 * HTTP status codes. | 12 * HTTP status codes. |
| 11 */ | 13 */ |
| 12 interface HTTPStatus { | 14 interface HTTPStatus { |
| 13 static final int CONTINUE = 100; | 15 static final int CONTINUE = 100; |
| 14 static final int SWITCHING_PROTOCOLS = 101; | 16 static final int SWITCHING_PROTOCOLS = 101; |
| 15 static final int OK = 200; | 17 static final int OK = 200; |
| 16 static final int CREATED = 201; | 18 static final int CREATED = 201; |
| 17 static final int ACCEPTED = 202; | 19 static final int ACCEPTED = 202; |
| (...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 135 * Returns the parsed query string. | 137 * Returns the parsed query string. |
| 136 */ | 138 */ |
| 137 Map<String, String> get queryParameters(); | 139 Map<String, String> get queryParameters(); |
| 138 | 140 |
| 139 /** | 141 /** |
| 140 * Returns the request headers. | 142 * Returns the request headers. |
| 141 */ | 143 */ |
| 142 Map<String, String> get headers(); | 144 Map<String, String> get headers(); |
| 143 | 145 |
| 144 /** | 146 /** |
| 145 * Sets the handler that gets called as request data becomes | 147 * Returns the input stream for the request. This is used to read |
| 146 * available. The data delivered are the raw bytes received. If the | 148 * the request data. |
| 147 * data is UTF-8 encoded and this callback is not set the callback | |
| 148 * [dataEnd] will be called with the decoded [String]. | |
| 149 */ | 149 */ |
| 150 void set dataReceived(void handler(List<int> data)); | 150 InputStream get inputStream(); |
| 151 | |
| 152 /** | |
| 153 * Sets the handler that gets called when all request data have been | |
| 154 * received. If the callback [dataReceived] is set the [String] | |
| 155 * argument will be [null] otherwise it will be the result of UTF-8 | |
| 156 * decoding the request body, | |
| 157 */ | |
| 158 void set dataEnd(void handler(String data)); | |
| 159 } | 151 } |
| 160 | 152 |
| 161 | 153 |
| 162 /** | 154 /** |
| 163 * HTTP response to be send back to the client. | 155 * HTTP response to be send back to the client. |
| 164 */ | 156 */ |
| 165 interface HTTPResponse default _HTTPResponse { | 157 interface HTTPResponse default _HTTPResponse { |
| 166 /** | 158 /** |
| 167 * Gets and sets the content length of the response. If the size of | 159 * Gets and sets the content length of the response. If the size of |
| 168 * the response is not known in advance set the content length to | 160 * the response is not known in advance set the content length to |
| (...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 339 * Returns the keep alive state of the connection. | 331 * Returns the keep alive state of the connection. |
| 340 */ | 332 */ |
| 341 bool get keepAlive(); | 333 bool get keepAlive(); |
| 342 | 334 |
| 343 /** | 335 /** |
| 344 * Returns the response headers. | 336 * Returns the response headers. |
| 345 */ | 337 */ |
| 346 Map get headers(); | 338 Map get headers(); |
| 347 | 339 |
| 348 /** | 340 /** |
| 349 * Sets callback to be called as request data becomes available. The | 341 * Returns the input stream for the response. This is used to read |
| 350 * data delivered are the raw received. If the data is UTF-8 encoded | 342 * the response data. |
| 351 * and this callback is not set the callback [dataEnd] will be | |
| 352 * called with the decoded [String]. | |
| 353 */ | 343 */ |
| 354 void set dataReceived(void callback(List<int> data)); | 344 InputStream get inputStream(); |
| 355 | |
| 356 /** | |
| 357 * Sets the callback to be called when all request data have been | |
| 358 * received. If the callback [dataReceived] is set the [String] | |
| 359 * argument will be [null] otherwise it will be the result of UTF-8 | |
| 360 * decoding the request body, | |
| 361 */ | |
| 362 void set dataEnd(void callback(String data)); | |
| 363 } | 345 } |
| 364 | 346 |
| 365 | 347 |
| 366 class HTTPException implements Exception { | 348 class HTTPException implements Exception { |
| 367 const HTTPException([String this.message = ""]); | 349 const HTTPException([String this.message = ""]); |
| 368 String toString() => "HTTPException: $message"; | 350 String toString() => "HTTPException: $message"; |
| 369 final String message; | 351 final String message; |
| 370 } | 352 } |
| OLD | NEW |