Changeset 12023 in project


Ignore:
Timestamp:
09/28/08 17:38:09 (12 years ago)
Author:
sjamaan
Message:

Implement request restarting

File:
1 edited

Legend:

Unmodified
Added
Removed
  • release/4/spiffy/trunk/spiffy.scm

    r12022 r12023  
    3838(module spiffy
    3939  (start-server with-headers send-status send-static-file
    40                 current-request current-response current-file current-pathinfo
    41                 root-path server-port index-files mime-type-map default-mime-type
    42                 default-host
    43                 handle-directory handle-not-found)
     40   current-request current-response current-file current-pathinfo
     41   root-path server-port index-files mime-type-map default-mime-type default-host
     42   handle-directory handle-not-found
     43   restart-request)
    4444
    4545(import chicken scheme extras ports files data-structures)
     
    9797                  "The resource you requested could not be found"))))
    9898
     99
     100;;; Internal parameters
     101(define request-restarter (make-parameter #f))
    99102
    100103(define (send-status code reason #!optional text)
     
    204207        (current-request))))
    205208
     209(define (restart-request req)
     210  ((request-restarter) req (request-restarter)))
     211
    206212(define (handle-incoming-request in out)
    207213  (parameterize ((current-request (read-request in))
     
    211217                                           `((content-type text/html))))))
    212218    (let ((path (uri-path (request-uri (current-request)))))
    213       (parameterize ((current-request (normalize-current-request-uri)))
    214             (if (and (uri-host (request-uri (current-request))) (pair? path))
    215                 (process-entry "" path)
    216                 ;; No host in the request? That's an error.
    217                 (send-status 400 "Bad request"
    218                              "Your client sent a request that the server did not understand")))
     219      (receive (req cont)
     220        (call/cc (lambda (c) (values (normalize-current-request-uri) c)))
     221        (parameterize ((current-request req)
     222                       (request-restarter cont))
     223          (if (and (uri-host (request-uri (current-request))) (pair? path))
     224              (process-entry "" path)
     225              ;; No host in the request? That's an error.
     226              (send-status 400 "Bad request"
     227                           "Your client sent a request that the server did not understand"))))
    219228      ;; For now, just close the ports and allow the thread to exit
    220229      (close-output-port out)
Note: See TracChangeset for help on using the changeset viewer.