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

Issue 10119005: Add HTTP handler registration to the HTTP server (Closed)

Created:
8 years, 8 months ago by Søren Gjesse
Modified:
8 years, 8 months ago
CC:
reviews_dartlang.org
Visibility:
Public.

Description

Add HTTP handler registration to the HTTP server NOTE: This is a breaking change. The onRequest callback on the HTTP server have been removed in favor of the ability to register handlers. A handler can be either a function or an instance of a class which implements a specific interface. Each handler registration has a regular expression which is matched against the request path. There is also a default handler which can be set to handle all requests which is not matched by any of the registered patterns. If there is no default handler explicitly set there is a builtin one which will just return 404 status. Currently the method is not considered in the matching. R=ager@google.com, ajohnsen@google.com BUG=none TEST=tests/standalone/src/io/HttpServerHandlerTest.dart Committed: https://code.google.com/p/dart/source/detail?r=6683

Patch Set 1 #

Total comments: 5

Patch Set 2 : Revert test edit #

Total comments: 13

Patch Set 3 : Addressed review comments #

Unified diffs Side-by-side diffs Delta from patch set Stats (+329 lines, -100 lines) Patch
M runtime/bin/http.dart View 1 2 3 chunks +27 lines, -5 lines 0 comments Download
M runtime/bin/http_impl.dart View 1 2 4 chunks +57 lines, -5 lines 0 comments Download
M samples/chat/chat_server_lib.dart View 1 2 5 chunks +35 lines, -63 lines 0 comments Download
M tests/standalone/src/io/HttpServerEarlyClientCloseTest.dart View 1 chunk +7 lines, -6 lines 0 comments Download
M tests/standalone/src/io/HttpServerEarlyServerCloseTest.dart View 1 chunk +4 lines, -3 lines 0 comments Download
A tests/standalone/src/io/HttpServerHandlerTest.dart View 1 2 1 chunk +179 lines, -0 lines 0 comments Download
M tests/standalone/src/io/HttpServerSocketTest.dart View 1 2 1 chunk +8 lines, -7 lines 0 comments Download
M tests/standalone/src/io/HttpServerTest.dart View 1 2 1 chunk +7 lines, -6 lines 0 comments Download
M tests/standalone/src/io/HttpShutdownTest.dart View 3 chunks +3 lines, -3 lines 0 comments Download
M tests/standalone/src/io/HttpTest.dart View 2 chunks +2 lines, -2 lines 0 comments Download

Messages

Total messages: 4 (0 generated)
Søren Gjesse
8 years, 8 months ago (2012-04-18 12:01:56 UTC) #1
Anders Johnsen
LGTM, Very nice, I like! https://chromiumcodereview.appspot.com/10119005/diff/3001/runtime/bin/http_impl.dart File runtime/bin/http_impl.dart (right): https://chromiumcodereview.appspot.com/10119005/diff/3001/runtime/bin/http_impl.dart#newcode799 runtime/bin/http_impl.dart:799: Object _handler; The type ...
8 years, 8 months ago (2012-04-18 12:19:09 UTC) #2
Mads Ager (google)
lgtm https://chromiumcodereview.appspot.com/10119005/diff/1/runtime/bin/http.dart File runtime/bin/http.dart (right): https://chromiumcodereview.appspot.com/10119005/diff/1/runtime/bin/http.dart#newcode56 runtime/bin/http.dart:56: * Interface to implement by HTTP request handler ...
8 years, 8 months ago (2012-04-18 12:22:08 UTC) #3
Søren Gjesse
8 years, 8 months ago (2012-04-18 13:26:56 UTC) #4
https://chromiumcodereview.appspot.com/10119005/diff/3001/runtime/bin/http.dart
File runtime/bin/http.dart (right):

https://chromiumcodereview.appspot.com/10119005/diff/3001/runtime/bin/http.da...
runtime/bin/http.dart:94: addRequestHandler(RegExp pattern, Object handler);
On 2012/04/18 12:22:08, Mads Ager wrote:
> I'm a little worried about forcing this to be a RegExp. How about using a
> function here instead of a regexp pattern:
> 
> bool match(String path)
> 
> Then for regexps you can do:
> 
> addRequestHandler(new RegExp('asdf').hasMatch, ...);
> 
> while at the same time allowing cheaper (or more flexible) matching routines.

Good point changed RegExp to a function that gets the request. Then the matching
can match on all properties of the request including path and method.

bool matcher(HttpRequest request)

https://chromiumcodereview.appspot.com/10119005/diff/3001/runtime/bin/http_im...
File runtime/bin/http_impl.dart (right):

https://chromiumcodereview.appspot.com/10119005/diff/3001/runtime/bin/http_im...
runtime/bin/http_impl.dart:799: Object _handler;
On 2012/04/18 12:19:09, ajohnsen wrote:
> The type could be either a Function or a RequestHandler. This would move the
> type checking to addRequestHandler/defaultRequestHandler.

Good point. Used RequestHandler and added the class _RequestHandlerImpl for
wrapping functions.

https://chromiumcodereview.appspot.com/10119005/diff/3001/runtime/bin/http_im...
runtime/bin/http_impl.dart:865: if
(_handlers[i]._pattern.hasMatch(request.path)) {
On 2012/04/18 12:19:09, ajohnsen wrote:
> What if we have multiple matches? Ignore? Should be documented.

The documentation in http.dart says that the first matching handler will handle
the request.

https://chromiumcodereview.appspot.com/10119005/diff/3001/runtime/bin/http_im...
runtime/bin/http_impl.dart:878: 
On 2012/04/18 12:22:08, Mads Ager wrote:
> Remove blank line?

Done.

https://chromiumcodereview.appspot.com/10119005/diff/3001/tests/standalone/sr...
File tests/standalone/src/io/HttpServerSocketTest.dart (right):

https://chromiumcodereview.appspot.com/10119005/diff/3001/tests/standalone/sr...
tests/standalone/src/io/HttpServerSocketTest.dart:182: };
On 2012/04/18 12:22:08, Mads Ager wrote:
> Slightly funky indentation. I think I prefer to add indentation for the
> end-brace here as well?

Absolutely, done.

https://chromiumcodereview.appspot.com/10119005/diff/3001/tests/standalone/sr...
File tests/standalone/src/io/HttpServerTest.dart (right):

https://chromiumcodereview.appspot.com/10119005/diff/3001/tests/standalone/sr...
tests/standalone/src/io/HttpServerTest.dart:26: };
On 2012/04/18 12:22:08, Mads Ager wrote:
> ditto

Done.

Powered by Google App Engine
This is Rietveld 408576698