diff --git a/collects/web-server/dispatch-servlets.ss b/collects/web-server/dispatch-servlets.ss index f09020bf81..78e9f97082 100644 --- a/collects/web-server/dispatch-servlets.ss +++ b/collects/web-server/dispatch-servlets.ss @@ -80,11 +80,10 @@ (lambda (the-exn) (output-response/method conn - ((responders-servlet-loading (host-responders - host-info)) uri - the-exn) - (request-method req)))]) - + ((responders-servlet-loading + (host-responders host-info)) + uri the-exn) + (request-method req)))]) (let ([sema (make-semaphore 0)] [last-inst (thread-cell-ref current-servlet-instance)]) (let/cc suspend @@ -180,7 +179,6 @@ (or (and (directory-exists? base) base) (loop base)))))) - ;; invoke-servlet-continuation: connection request continuation-reference ;; host -> void ;; pull the continuation out of the table and apply it diff --git a/collects/web-server/response.ss b/collects/web-server/response.ss index 0518a4093e..91e6eb4ff2 100644 --- a/collects/web-server/response.ss +++ b/collects/web-server/response.ss @@ -128,7 +128,7 @@ (response/full-body resp))))] [(response/incremental? resp) (output-response/incremental conn resp)] - [(and (pair? resp) (string? (car resp))) + [(and (pair? resp) (bytes? (car resp))) (output-response/basic conn (make-response/basic 200 "Okay" (current-seconds) (car resp) '()) diff --git a/collects/web-server/web-server-unit.ss b/collects/web-server/web-server-unit.ss index 7dc3f7d3ee..07e5f4486a 100644 --- a/collects/web-server/web-server-unit.ss +++ b/collects/web-server/web-server-unit.ss @@ -150,28 +150,44 @@ ;; NOTE: (GregP) I'm going to use the dispatch logic out of v208 for now. ;; I will move the other dispatch logic out of the prototype ;; at a later time. - (define (dispatch conn req) - (let* ([host (get-host (request-uri req) (request-headers req))] - [host-info (config:virtual-hosts host)]) - ((host-log-message host-info) (request-host-ip req) - (request-client-ip req) (request-method req) (request-uri req) host) - ((sequencer:gen-dispatcher - (passwords:gen-dispatcher host-info config:access) - (path-procedure:gen-dispatcher "/conf/collect-garbage" - (lambda () - (collect-garbage) - ((responders-collect-garbage (host-responders host-info))))) - (servlets:gen-dispatcher host-info - config:instances config:scripts config:scripts-lock config:make-servlet-namespace) - (files:gen-dispatcher host-info)) - conn req))))) + (define dispatch + (let* ([cache (make-hash-table 'equal)] + [sema (make-semaphore 1)] + [lookup-dispatcher + (lambda (host host-info) + (hash-table-get + cache host + (lambda () + (call-with-semaphore + sema (lambda () + (hash-table-get + cache host + (lambda () (host-info->dispatcher host-info))))))))]) + (lambda (conn req) + (let* ([host (get-host (request-uri req) (request-headers req))] + [host-info (config:virtual-hosts host)]) + ((host-log-message host-info) (request-host-ip req) + (request-client-ip req) (request-method req) (request-uri req) host) + ((lookup-dispatcher host host-info) + conn req))))) + + (define (host-info->dispatcher host-info) + (sequencer:gen-dispatcher + (passwords:gen-dispatcher host-info config:access) + (path-procedure:gen-dispatcher "/conf/collect-garbage" + (lambda () + (collect-garbage) + ((responders-collect-garbage (host-responders host-info))))) + (servlets:gen-dispatcher host-info + config:instances config:scripts config:scripts-lock config:make-servlet-namespace) + (files:gen-dispatcher host-info))))) (define web-server@ (compound-unit/sig (import (TCP : net:tcp^) (CONFIG : web-config^)) - (link (DISPATCH : dispatch-server^ - (dispatch-server@ TCP DISPATCH-CONFIG)) - (DISPATCH-CONFIG : dispatch-server-config^ - (web-config@->dispatch-server-config@ CONFIG))) - (export (open (DISPATCH : web-server^)))))) \ No newline at end of file + (link (DISPATCH-CONFIG : dispatch-server-config^ + (web-config@->dispatch-server-config@ CONFIG)) + (DISPATCH : dispatch-server^ + (dispatch-server@ TCP DISPATCH-CONFIG))) + (export (open (DISPATCH : web-server^))))))