Learn how easy it is to sync an existing GitHub or Google Code repo to a SourceForge project! See Demo

Close

#4 Add wildcard calbacks to http.c

open
Niels Provos
None
5
2010-01-23
2007-11-06
Nick Mathewson
No

In the Oct 2007 thread "How to make a Generic handler ?" , "William" proposes that evhttp_set_cb be extended so that instead of taking entire URLs, it can take URL pefixes.

He includes a patch that makes this the default behavior. Instead, this should probably be implemented only as a new callback type, so as not to break old code.

Discussion

  • Niels Provos
    Niels Provos
    2007-11-13

    Logged In: YES
    user_id=245089
    Originator: NO

    How about using a * as wild card? evhttp_set_cb(http, "/static/*", static_handler, NULL)? Would be backwards compatible and not break existing behavior.

     
  • Nick Mathewson
    Nick Mathewson
    2007-11-14

    Logged In: YES
    user_id=499
    Originator: YES

    That sounds reasonable, but a little worrisome. How will it interact with URI decoding? Will we have to support wildcards in all positions in the URI?

     
  • Niels Provos
    Niels Provos
    2007-11-14

    Logged In: YES
    user_id=245089
    Originator: NO

    I don't really want to over complicate it. I was thinking of allowing suffix matching. If somebody completely wants to override the current mechanism they can just set a default callback and get all requests that way. However, I can see situations where just a suffix match would be nice to have.

    It should not interact with URI encoding/decoding at all.

     
  • Nick Mathewson
    Nick Mathewson
    2007-11-17

    Logged In: YES
    user_id=499
    Originator: YES

    My question about URI encoding/decoding is this: do we do URL matching before or after decoding? IMO we need to match URIs after decoding, otherwise we can't realize that
    "/libevent.html" and "/libevent.htm%6c" are actually the same resource. But if we have decoded the URI, it's legal for it to have a star in it. If we make "*" at the end of a URI match any suffix, it will no longer be possible to have a handler that matches a request for "/stuff/%2a" (which decodes to /stuff/*) but not "/stuff/%2b".

    The standard thing to do here is to add some way to escape wildcards, or use something other than wildcards to indicate that prefix matching is desired.

     
  • Niels Provos
    Niels Provos
    2007-11-18

    Logged In: YES
    user_id=245089
    Originator: NO

    I think a better approach would be to add a new function; something like

    evhttp_add_cb(http_server, MATCH_TYPE, callback_function, callback_arg)

    where MATCH_TYPE initially might be exact match and prefix match. This way we could extend it to substring, regular expression or some such in the future.

     
  • Nick Mathewson
    Nick Mathewson
    2007-11-19

    Logged In: YES
    user_id=499
    Originator: YES

    I'm guessing that evhttp_add_cb would also need an argument to say what to match, right? So it signature would be
    evhttp_add_cb(struct evhttp *server, int match_type, void *match_data,
    void (*callback_fn)(struct evhttp_request *, void *), void *data);

    and you'd call it something like
    evhttp_add_cb(server, EVHTTP_MATCH_EXACT, "/images/im1.jpg", im1_callback, NULL);
    or
    evhttp_add_cb(server, EVHTTP_MATCH_PREFIX, "/cgi-bin/", scripts_callback, NULL);

     
  • Nick Mathewson
    Nick Mathewson
    2007-11-19

    Logged In: YES
    user_id=499
    Originator: YES

    NOTE: Because it was possible to work around this feature in libevent 1.3*, but it isn't in 1.4 (because we declare more functions static), we should probably treat this as a bugfix.

     
  • Nick Mathewson
    Nick Mathewson
    2007-11-22

    Logged In: YES
    user_id=499
    Originator: YES

    On 22 Nov 2007, William mentioned that it would be neat to support virtual hosts too. It would be nice to get this in as part of the interface as well.

     
  • Niels Provos
    Niels Provos
    2007-11-25

    Logged In: YES
    user_id=245089
    Originator: NO

    I am fine with adding a host field to the add callback function. However, this should probably be a precise host match and not include yet another way for things to get matched differently. For special needs there always is the general callback handler. To make this more efficient you probably want to use something better than a linked list. Ideally, we would use hash table for host lookup, in the past, I usually punted and used my tree macros instead.

     
  • Nick Mathewson
    Nick Mathewson
    2010-01-23

    • assigned_to: nobody --> nprovos