Chromium Code Reviews| Index: runtime/bin/http.dart |
| diff --git a/runtime/bin/http.dart b/runtime/bin/http.dart |
| index 6c38c28f7423095c2ed30e1bb5bc61de1fc8d945..4fcafd6cf7b8998322996f5ab951c9678985c5ab 100644 |
| --- a/runtime/bin/http.dart |
| +++ b/runtime/bin/http.dart |
| @@ -53,6 +53,15 @@ interface HttpStatus { |
| /** |
| + * Interface to implement by HTTP request handler classes. |
| + */ |
| + |
| +interface RequestHandler { |
| + void onRequest(HttpRequest request, HttpResponse response); |
| +} |
| + |
| + |
| +/** |
| * HTTP server. |
| */ |
| interface HttpServer default _HttpServer { |
| @@ -76,6 +85,23 @@ interface HttpServer default _HttpServer { |
| void listenOn(ServerSocket serverSocket); |
| /** |
| + * Adds a request handler to the list of request handlers. The |
| + * request path is matched against the specified pattern. The first |
| + * handler for which pattern which matches will be handed the |
| + * request. The [handler] can be either an object implementing the |
| + * [RequestHandler] interface or a function taking two arguments. |
| + */ |
| + addRequestHandler(RegExp pattern, Object handler); |
|
Mads Ager (google)
2012/04/18 12:22:08
I'm a little worried about forcing this to be a Re
Søren Gjesse
2012/04/18 13:26:56
Good point changed RegExp to a function that gets
|
| + |
| + /** |
| + * Sets the request handler. This request handler will be called if |
| + * none of the request handlers registered by [addRequestHandler] |
| + * matches the current request. If no default request handler is set |
| + * the server will just respond with status code [:NOT_FOUND:] (404). |
| + */ |
| + void set defaultRequestHandler(Object handler); |
| + |
| + /** |
| * Stop server listening. |
| */ |
| void close(); |
| @@ -88,11 +114,6 @@ interface HttpServer default _HttpServer { |
| int get port(); |
| /** |
| - * Sets the handler that gets called when a new HTTP request is received. |
| - */ |
| - void set onRequest(void callback(HttpRequest, HttpResponse)); |
| - |
| - /** |
| * Sets the error handler that is called when a connection error occurs. |
| */ |
| void set onError(void callback(Exception e)); |