Re: [Chicken-users] Spiffy Question: handle-not-found
On Sun, 2010-02-14 at 18:17 +0100, Peter Bex wrote: On Sun, Feb 14, 2010 at 11:39:18AM -0500, Taylor Venable wrote: The Spiffy documentation says about the value of handle-not-found: It is a procedure of one argument, the path (a string) that was requested. However, it seems that the actual argument is the path, up until the first component which was not found. If root-path does not exist, path is always /. If root-path does exist, but neither foo nor asdf exist within it, then path is always /foo or /asdf. That's what it seems to be, anyway; is that the correct behaviour? If nobody objects, I could change the handler to pass the remaining path to (handle-not-found) as a second argument. Unfortunately this would be a backwards-incompatible change, though. This would be a list of remaining path components. No need to make a breaking change on my account, I've got what I need by using intarweb and uri-common. I just noticed an incongruity between my understanding of the doc and the actual behavior, trying to figure out which one was right. Recently there have been a few new eggs created for dispatching URIs. You might find those interesting: http://chicken.wiki.br/eggref/4/spiffy-uri-match (or more generally http://chicken.wiki.br/eggref/4/uri-match ) http://chicken.wiki.br/eggref/4/uri-dispatch and a more generic web framework was created as well: http://chicken.wiki.br/eggref/4/awful If you prefer simplicity, you could also use Andrew Wright's pattern matcher on the uri-path: http://chicken.wiki.br/eggref/4/matchable Sweet, these look useful. Fortunately my app is pretty simple right now, but if it gets more complicated these will definitely help. Thanks for the insight. -- Taylor Venable http://metasyntax.net/ ___ Chicken-users mailing list Chicken-users@nongnu.org http://lists.nongnu.org/mailman/listinfo/chicken-users
[Chicken-users] Spiffy Question: handle-not-found
Hi, I'm using Spiffy and setting handle-not-found in an attempt to use Spiffy like a generic URL-based dispatcher. For example, when the user requests /foo/bar I want to send back the result of calling function x, and when the user requests /asdf/jkl I want to send back the result of calling function y: (handle-not-found (lambda (path) (log-to (debug-log) REQUEST: ~s path) (cond ((string=? uri /foo/bar) (x)) ((string=? uri /asdf/jkl) (y)) (else (handle-other) The Spiffy documentation says about the value of handle-not-found: It is a procedure of one argument, the path (a string) that was requested. However, it seems that the actual argument is the path, up until the first component which was not found. If root-path does not exist, path is always /. If root-path does exist, but neither foo nor asdf exist within it, then path is always /foo or /asdf. That's what it seems to be, anyway; is that the correct behaviour? It seems to be slightly different from what the documentation says, since it is not necessarily the requested path. In the meantime I've been using this code as a workaround to get what I want regardless of the existence of files in the path: (string-join (cdr (uri-path (request-uri (current-request / 'prefix) Thanks for the clarification, -- Taylor Venable http://metasyntax.net/ ___ Chicken-users mailing list Chicken-users@nongnu.org http://lists.nongnu.org/mailman/listinfo/chicken-users
Re: [Chicken-users] Spiffy Question: handle-not-found
On Sun, Feb 14, 2010 at 11:39:18AM -0500, Taylor Venable wrote: The Spiffy documentation says about the value of handle-not-found: It is a procedure of one argument, the path (a string) that was requested. However, it seems that the actual argument is the path, up until the first component which was not found. If root-path does not exist, path is always /. If root-path does exist, but neither foo nor asdf exist within it, then path is always /foo or /asdf. That's what it seems to be, anyway; is that the correct behaviour? Good question, I'm not 100% sure myself :) The idea here would be that the not-found handler should indeed be able to handle whatever part of the path was not found, so this information is very useful but missing. If nobody objects, I could change the handler to pass the remaining path to (handle-not-found) as a second argument. Unfortunately this would be a backwards-incompatible change, though. This would be a list of remaining path components. It seems to be slightly different from what the documentation says, since it is not necessarily the requested path. Yeah, if nothing else it's surely a documentation bug. In the meantime I've been using this code as a workaround to get what I want regardless of the existence of files in the path: (string-join (cdr (uri-path (request-uri (current-request / 'prefix) Yeah, this workaround should more or less work. There's one caveat: By doing it this way, encoded slashes will be indistinguishable from path-separating slashes. Recently there have been a few new eggs created for dispatching URIs. You might find those interesting: http://chicken.wiki.br/eggref/4/spiffy-uri-match (or more generally http://chicken.wiki.br/eggref/4/uri-match ) http://chicken.wiki.br/eggref/4/uri-dispatch and a more generic web framework was created as well: http://chicken.wiki.br/eggref/4/awful If you prefer simplicity, you could also use Andrew Wright's pattern matcher on the uri-path: http://chicken.wiki.br/eggref/4/matchable Cheers, Peter -- http://sjamaan.ath.cx -- The process of preparing programs for a digital computer is especially attractive, not only because it can be economically and scientifically rewarding, but also because it can be an aesthetic experience much like composing poetry or music. -- Donald Knuth ___ Chicken-users mailing list Chicken-users@nongnu.org http://lists.nongnu.org/mailman/listinfo/chicken-users
Re: [Chicken-users] Spiffy Question: handle-not-found
I made a mistake when copying this example from the real source code; it should have read: (handle-not-found (lambda (path) (log-to (debug-log) REQUEST: ~s path) (cond ((string=? path /foo/bar); s/uri/path/ (x)) ((string=? path /asdf/jkl) ; s/uri/path/ (y)) (else (handle-other) Where x and y do their own header setup, and write their own output. -- Taylor Venable http://metasyntax.net/ ___ Chicken-users mailing list Chicken-users@nongnu.org http://lists.nongnu.org/mailman/listinfo/chicken-users