Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(33)

Unified Diff: runtime/bin/http.dart

Issue 10119005: Add HTTP handler registration to the HTTP server (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Revert test edit Created 8 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | runtime/bin/http_impl.dart » ('j') | runtime/bin/http_impl.dart » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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));
« no previous file with comments | « no previous file | runtime/bin/http_impl.dart » ('j') | runtime/bin/http_impl.dart » ('J')

Powered by Google App Engine
This is Rietveld 408576698