| 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 /** | 5 /** |
| 6 * HTTP status codes. | 6 * HTTP status codes. |
| 7 */ | 7 */ |
| 8 interface HttpStatus { | 8 interface HttpStatus { |
| 9 static final int CONTINUE = 100; | 9 static final int CONTINUE = 100; |
| 10 static final int SWITCHING_PROTOCOLS = 101; | 10 static final int SWITCHING_PROTOCOLS = 101; |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 53 | 53 |
| 54 | 54 |
| 55 /** | 55 /** |
| 56 * HTTP server. | 56 * HTTP server. |
| 57 */ | 57 */ |
| 58 interface HttpServer default _HttpServer { | 58 interface HttpServer default _HttpServer { |
| 59 HttpServer(); | 59 HttpServer(); |
| 60 | 60 |
| 61 /** | 61 /** |
| 62 * Start listening for HTTP requests on the specified [host] and | 62 * Start listening for HTTP requests on the specified [host] and |
| 63 * [port]. For each HTTP request the handler set through | 63 * [port]. For each HTTP request the handler set through [onRequest] |
| 64 * [requestHandler] will be invoked. If a [port] of 0 is specified | 64 * will be invoked. If a [port] of 0 is specified the server will |
| 65 * the server will choose an ephemeral port. The optional argument | 65 * choose an ephemeral port. The optional argument [backlog] can be |
| 66 * [backlog] can be used to specify the listen backlog for the | 66 * used to specify the listen backlog for the underlying OS listen |
| 67 * underlying OS listen setup. | 67 * setup. |
| 68 */ | 68 */ |
| 69 void listen(String host, int port, [int backlog]); | 69 void listen(String host, int port, [int backlog]); |
| 70 | 70 |
| 71 /** | 71 /** |
| 72 * Stop server listening. | 72 * Stop server listening. |
| 73 */ | 73 */ |
| 74 void close(); | 74 void close(); |
| 75 | 75 |
| 76 /** | 76 /** |
| 77 * Returns the port that the server is listening on. This can be | 77 * Returns the port that the server is listening on. This can be |
| 78 * used to get the actual port used when a value of 0 for [port] is | 78 * used to get the actual port used when a value of 0 for [port] is |
| 79 * specified in the [listen] call. | 79 * specified in the [listen] call. |
| 80 */ | 80 */ |
| 81 int get port(); | 81 int get port(); |
| 82 | 82 |
| 83 /** | 83 /** |
| 84 * Sets the handler that gets called when a new HTTP request is received. | 84 * Sets the handler that gets called when a new HTTP request is received. |
| 85 */ | 85 */ |
| 86 void set requestHandler(void handler(HttpRequest, HttpResponse)); | 86 void set onRequest(void handler(HttpRequest, HttpResponse)); |
| 87 | 87 |
| 88 /** | 88 /** |
| 89 * Sets the error handler that is called when a connection error occurs. | 89 * Sets the error handler that is called when a connection error occurs. |
| 90 */ | 90 */ |
| 91 void set errorHandler(void handler(String errorMessage)); | 91 void set onError(void handler(String errorMessage)); |
| 92 } | 92 } |
| 93 | 93 |
| 94 | 94 |
| 95 /** | 95 /** |
| 96 * Http request delivered to the HTTP server callback. | 96 * Http request delivered to the HTTP server callback. |
| 97 */ | 97 */ |
| 98 interface HttpRequest default _HttpRequest { | 98 interface HttpRequest default _HttpRequest { |
| 99 /** | 99 /** |
| 100 * Returns the content length of the request body. If the size of | 100 * Returns the content length of the request body. If the size of |
| 101 * the request body is not known in advance this -1. | 101 * the request body is not known in advance this -1. |
| (...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 232 */ | 232 */ |
| 233 void shutdown(); | 233 void shutdown(); |
| 234 } | 234 } |
| 235 | 235 |
| 236 | 236 |
| 237 /** | 237 /** |
| 238 * A [HttpClientConnection] is returned by all [HttpClient] methods | 238 * A [HttpClientConnection] is returned by all [HttpClient] methods |
| 239 * that initiate a connection to an HTTP server. The handlers will be | 239 * that initiate a connection to an HTTP server. The handlers will be |
| 240 * called as the connection state progresses. | 240 * called as the connection state progresses. |
| 241 * | 241 * |
| 242 * The setting of all handlers is optional. If the [requestHandler] is | 242 * The setting of all handlers is optional. If [onRequest] is not set |
| 243 * not set the request will be send without any additional headers and | 243 * the request will be send without any additional headers and an |
| 244 * an empty body. If the [responseHandler] is not set the response | 244 * empty body. If [onResponse] is not set the response will be read |
| 245 * will be read and discarded. | 245 * and discarded. |
| 246 */ | 246 */ |
| 247 interface HttpClientConnection { | 247 interface HttpClientConnection { |
| 248 /** | 248 /** |
| 249 * Sets the handler that is called when the connection is established. | 249 * Sets the handler that is called when the connection is established. |
| 250 */ | 250 */ |
| 251 void set requestHandler(void handler(HttpClientRequest request)); | 251 void set onRequest(void handler(HttpClientRequest request)); |
| 252 | 252 |
| 253 /** | 253 /** |
| 254 * Sets callback to be called when the request has been send and | 254 * Sets callback to be called when the request has been send and |
| 255 * the response is ready for processing. The callback is called when | 255 * the response is ready for processing. The callback is called when |
| 256 * all headers of the response are received and data is ready to be | 256 * all headers of the response are received and data is ready to be |
| 257 * received. | 257 * received. |
| 258 */ | 258 */ |
| 259 void set responseHandler(void handler(HttpClientResponse response)); | 259 void set onResponse(void handler(HttpClientResponse response)); |
| 260 | 260 |
| 261 /** | 261 /** |
| 262 * Sets the handler that gets called if an error occurs while | 262 * Sets the handler that gets called if an error occurs while |
| 263 * processing the HTTP request. | 263 * processing the HTTP request. |
| 264 */ | 264 */ |
| 265 void set errorHandler(void handler(HttpException e)); | 265 void set onError(void handler(HttpException e)); |
| 266 } | 266 } |
| 267 | 267 |
| 268 | 268 |
| 269 /** | 269 /** |
| 270 * HTTP request for a client connection. | 270 * HTTP request for a client connection. |
| 271 */ | 271 */ |
| 272 interface HttpClientRequest default _HttpClientRequest { | 272 interface HttpClientRequest default _HttpClientRequest { |
| 273 /** | 273 /** |
| 274 * Gets and sets the content length of the request. If the size of | 274 * Gets and sets the content length of the request. If the size of |
| 275 * the request is not known in advance set content length to -1, | 275 * the request is not known in advance set content length to -1, |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 346 */ | 346 */ |
| 347 InputStream get inputStream(); | 347 InputStream get inputStream(); |
| 348 } | 348 } |
| 349 | 349 |
| 350 | 350 |
| 351 class HttpException implements Exception { | 351 class HttpException implements Exception { |
| 352 const HttpException([String this.message = ""]); | 352 const HttpException([String this.message = ""]); |
| 353 String toString() => "HttpException: $message"; | 353 String toString() => "HttpException: $message"; |
| 354 final String message; | 354 final String message; |
| 355 } | 355 } |
| OLD | NEW |