[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Chicken-hackers] URL dispatching for http-server
From: |
Mario Domenech Goulart |
Subject: |
[Chicken-hackers] URL dispatching for http-server |
Date: |
09 Oct 2006 17:55:44 -0300 |
User-agent: |
Gnus/5.09 (Gnus v5.9.0) Emacs/21.4 |
Hello,
I'm playing with a code (attached) to allow mapping URLs to Scheme
procedures. It's supposed to work with http-server (and spiffy).
Example:
An access to
http://myserver.net/add/1/2
would ask spiffy to execute
(add "1" "2")
To achieve that, currently I have to do the following:
;; register the path from which the URL->procedure mapping should be
;; considered. E.g., this tells http-server that the first "path
;; part", counting from the given path (`/'), should be considered a
;; procedure name and the remaining "path part" the arguments.
(register-dispatcher "/")
;; define a procedure and add it to a list of procedures which can
;; be safely executed from an URL. Attempts to call procedures not
;; defined with `define-callable-url' should fail.
(define-callable-url (add . args)
(apply + (map string->number args)))
Now the questions:
1. I had to hack the http-server's `http:find-resource' procedure to
match regex patterns instead of plain strings.
(define (http:find-resource url)
(let loop ((keys (hash-table-keys resource-table)))
(and-let* (((not (null? keys)))
(current-key (car keys)))
(if (string-match current-key url)
(hash-table-ref resource-table current-key)
(loop (cdr keys))))))
1.1. Is it necessary? Can http-server do something similar without
this modification? I need this to match _any_ request from a given
path.
1.2. Are there security or backwards compatibility issues regarding
to this change?
2. Is there a "standard" name for this kind of feature (what I'm
calling "url-dispatching" -- stolen from Django, which seems to
implement something similar, as far as I understand)?
3. Comments?
Best wishes,
Mario
url-dispatcher.scm
Description: Binary data
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Chicken-hackers] URL dispatching for http-server,
Mario Domenech Goulart <=