Welcome to the CHICKEN Scheme pasting service

Another spiffy uri rewriting question added by mario-goulart on Mon Jun 11 21:52:10 2012

$ ls -l
total 4
drwxr-xr-x 2 mario mario 104 Jun 11 16:31 bar
drwxr-xr-x 2 mario mario  80 Jun 11 16:31 foo
-rw-r--r-- 1 mario mario 760 Jun 11 16:47 server.scm

$ ls -l bar/
total 4
-rw-r--r-- 1 mario mario 10 Jun 11 16:31 index.html

$ cat bar/index.html 
index bar

$ ls -l foo/
total 4
-rw-r--r-- 1 mario mario 10 Jun 11 16:31 index.html

$ cat foo/index.html 
index foo

$ cat server.scm 
(use spiffy intarweb uri-common)

(define (drop-bar-from-requested-path)
  (let* ((req (current-request))
         (uri (request-uri req))
         (rest (cddr (uri-path uri)))) ; drop bar
    (update-request req
                    uri: (update-uri (request-uri req)
                                     path: (cons '/ rest)))))


(define (bar-request?)
  (let ((path (uri-path (request-uri (current-request)))))
    (and (not (null? (cdr path)))
         (equal? (cadr path) "bar"))))

(vhost-map
 `((".*" .
    ,(lambda (continue)
       (cond
        ;; bar
        ((bar-request?)
         (parameterize ((root-path "bar")
                        (current-request (drop-bar-from-requested-path)))
           (continue)))
        (else
         ;; foo
         (parameterize ((root-path "foo"))
           (continue))))))))

(start-server)


$ csi -s server.scm &

$ wget -qO - http://localhost:8080/
index foo

$ wget -qO - http://localhost:8080/bar/
index bar

$ wget -qO - http://localhost:8080/bar
index foo                                        <-- WHY?

Your annotation:

Enter a new annotation:

Your nick:
The title of your paste:
Your paste (mandatory) :
Name of the bot in #chicken:
Visually impaired? Let me spell it for you (wav file) download WAV