Simplifying
svn: r6619
This commit is contained in:
parent
5c0698e07d
commit
7bd7135fb3
|
@ -16,7 +16,8 @@
|
||||||
"../managers/lru.ss"
|
"../managers/lru.ss"
|
||||||
"../managers/none.ss"
|
"../managers/none.ss"
|
||||||
"../private/servlet.ss"
|
"../private/servlet.ss"
|
||||||
"../private/cache-table.ss")
|
"../private/cache-table.ss"
|
||||||
|
"../private/util.ss")
|
||||||
(provide/contract
|
(provide/contract
|
||||||
[interface-version dispatcher-interface-version?])
|
[interface-version dispatcher-interface-version?])
|
||||||
(provide make)
|
(provide make)
|
||||||
|
@ -41,23 +42,13 @@
|
||||||
(adjust-connection-timeout!
|
(adjust-connection-timeout!
|
||||||
conn
|
conn
|
||||||
timeouts-servlet-connection)
|
timeouts-servlet-connection)
|
||||||
; XXX Allow servlet to respond
|
(cond
|
||||||
(case meth
|
[(continuation-url? uri)
|
||||||
[(head)
|
=> (match-lambda
|
||||||
(output-response/method
|
[(list instance-id k-id salt)
|
||||||
conn
|
(invoke-servlet-continuation conn req instance-id k-id salt)])]
|
||||||
(make-response/full
|
|
||||||
200 "Okay" (current-seconds) TEXT/HTML-MIME-TYPE
|
|
||||||
'() (list "ignored"))
|
|
||||||
meth)]
|
|
||||||
[else
|
[else
|
||||||
(cond
|
(servlet-content-producer/path conn req uri)]))
|
||||||
[(continuation-url? uri)
|
|
||||||
=> (match-lambda
|
|
||||||
[(list instance-id k-id salt)
|
|
||||||
(invoke-servlet-continuation conn req instance-id k-id salt)])]
|
|
||||||
[else
|
|
||||||
(servlet-content-producer/path conn req uri)])]))
|
|
||||||
|
|
||||||
;; servlet-content-producer/path: connection request url -> void
|
;; servlet-content-producer/path: connection request url -> void
|
||||||
;; This is not a continuation url so the loading behavior is determined
|
;; This is not a continuation url so the loading behavior is determined
|
||||||
|
@ -84,7 +75,7 @@
|
||||||
(exn-message e)
|
(exn-message e)
|
||||||
(exn-continuation-marks e))))])
|
(exn-continuation-marks e))))])
|
||||||
(url->path uri)))
|
(url->path uri)))
|
||||||
(parameterize ([current-directory (get-servlet-base-dir servlet-path)]
|
(parameterize ([current-directory (directory-part servlet-path)]
|
||||||
[current-custodian instance-custodian]
|
[current-custodian instance-custodian]
|
||||||
[exit-handler
|
[exit-handler
|
||||||
(lambda (v)
|
(lambda (v)
|
||||||
|
@ -101,7 +92,10 @@
|
||||||
(define instance-id ((manager-create-instance manager) (make-servlet-instance-data servlet-mutex) (exit-handler)))
|
(define instance-id ((manager-create-instance manager) (make-servlet-instance-data servlet-mutex) (exit-handler)))
|
||||||
(parameterize ([current-servlet-instance-id instance-id])
|
(parameterize ([current-servlet-instance-id instance-id])
|
||||||
(with-handlers ([(lambda (x) #t)
|
(with-handlers ([(lambda (x) #t)
|
||||||
(make-servlet-exception-handler)])
|
(lambda (exn)
|
||||||
|
(responders-servlet
|
||||||
|
(request-uri req)
|
||||||
|
exn))])
|
||||||
((servlet-handler the-servlet) req))))))))
|
((servlet-handler the-servlet) req))))))))
|
||||||
servlet-prompt)))))
|
servlet-prompt)))))
|
||||||
(output-response conn response))
|
(output-response conn response))
|
||||||
|
@ -110,22 +104,6 @@
|
||||||
(define (default-servlet-instance-expiration-handler req)
|
(define (default-servlet-instance-expiration-handler req)
|
||||||
(next-dispatcher))
|
(next-dispatcher))
|
||||||
|
|
||||||
;; make-servlet-exception-handler: servlet-instance -> exn -> void
|
|
||||||
(define ((make-servlet-exception-handler) the-exn)
|
|
||||||
(responders-servlet
|
|
||||||
(request-uri (execution-context-request (current-execution-context)))
|
|
||||||
the-exn))
|
|
||||||
|
|
||||||
;; path -> path
|
|
||||||
;; The actual servlet's parent directory.
|
|
||||||
(define (get-servlet-base-dir servlet-path)
|
|
||||||
(let loop ([path servlet-path])
|
|
||||||
(define-values (base name must-be-dir?) (split-path path))
|
|
||||||
(or (if must-be-dir?
|
|
||||||
(and (directory-exists? path) path)
|
|
||||||
(and (directory-exists? base) base))
|
|
||||||
(loop base))))
|
|
||||||
|
|
||||||
(define (invoke-servlet-continuation conn req instance-id k-id salt)
|
(define (invoke-servlet-continuation conn req instance-id k-id salt)
|
||||||
(define uri (request-uri req))
|
(define uri (request-uri req))
|
||||||
(define-values (servlet-path _) (url->path uri))
|
(define-values (servlet-path _) (url->path uri))
|
||||||
|
@ -134,7 +112,7 @@
|
||||||
(define data ((manager-instance-lookup-data manager) instance-id))
|
(define data ((manager-instance-lookup-data manager) instance-id))
|
||||||
(define response
|
(define response
|
||||||
(parameterize ([current-servlet the-servlet]
|
(parameterize ([current-servlet the-servlet]
|
||||||
[current-directory (get-servlet-base-dir servlet-path)]
|
[current-directory (directory-part servlet-path)]
|
||||||
[current-servlet-instance-id instance-id]
|
[current-servlet-instance-id instance-id]
|
||||||
[current-custodian (servlet-custodian the-servlet)]
|
[current-custodian (servlet-custodian the-servlet)]
|
||||||
[current-namespace (servlet-namespace the-servlet)]
|
[current-namespace (servlet-namespace the-servlet)]
|
||||||
|
@ -190,25 +168,21 @@
|
||||||
(format "Couldn't find ~a" servlet-filename)
|
(format "Couldn't find ~a" servlet-filename)
|
||||||
(current-continuation-marks) ))]))
|
(current-continuation-marks) ))]))
|
||||||
|
|
||||||
;; load-servlet/path path -> (or/c #f cache-entry)
|
(define (v0.response->v1.lambda response response-path)
|
||||||
;; given a string path to a filename attempt to load a servlet
|
(define go
|
||||||
;; A servlet-file will contain either
|
(box
|
||||||
;;;; A signed-unit-servlet
|
(lambda ()
|
||||||
;;;; A module servlet, currently only 'v1
|
(set-box! go (lambda () (load/use-compiled response-path)))
|
||||||
;;;; A response
|
response)))
|
||||||
|
(lambda (initial-request)
|
||||||
|
((unbox go))))
|
||||||
|
(define (v1.module->v1.lambda timeout start)
|
||||||
|
(lambda (initial-request)
|
||||||
|
(adjust-timeout! timeout)
|
||||||
|
(start initial-request)))
|
||||||
|
|
||||||
|
;; load-servlet/path path -> servlet
|
||||||
(define (load-servlet/path a-path)
|
(define (load-servlet/path a-path)
|
||||||
(define (v0.response->v1.lambda response-path response)
|
|
||||||
(define go
|
|
||||||
(box
|
|
||||||
(lambda ()
|
|
||||||
(set-box! go (lambda () (load/use-compiled a-path)))
|
|
||||||
response)))
|
|
||||||
(lambda (initial-request)
|
|
||||||
((unbox go))))
|
|
||||||
(define (v1.module->v1.lambda timeout start)
|
|
||||||
(lambda (initial-request)
|
|
||||||
(adjust-timeout! timeout)
|
|
||||||
(start initial-request)))
|
|
||||||
(parameterize ([current-namespace (config:make-servlet-namespace
|
(parameterize ([current-namespace (config:make-servlet-namespace
|
||||||
#:additional-specs
|
#:additional-specs
|
||||||
'((lib "servlet.ss" "web-server")
|
'((lib "servlet.ss" "web-server")
|
||||||
|
@ -220,7 +194,6 @@
|
||||||
(define s (load/use-compiled a-path))
|
(define s (load/use-compiled a-path))
|
||||||
(cond
|
(cond
|
||||||
; XXX - reason about exceptions from dynamic require (catch and report if not already)
|
; XXX - reason about exceptions from dynamic require (catch and report if not already)
|
||||||
;; module servlet
|
|
||||||
[(void? s)
|
[(void? s)
|
||||||
(let* ([module-name `(file ,(path->string a-path))]
|
(let* ([module-name `(file ,(path->string a-path))]
|
||||||
[version (dynamic-require module-name 'interface-version)])
|
[version (dynamic-require module-name 'interface-version)])
|
||||||
|
@ -254,7 +227,6 @@
|
||||||
start))]
|
start))]
|
||||||
[else
|
[else
|
||||||
(error 'load-servlet/path "unknown servlet version ~e" version)]))]
|
(error 'load-servlet/path "unknown servlet version ~e" version)]))]
|
||||||
;; response
|
|
||||||
[(response? s)
|
[(response? s)
|
||||||
(make-servlet (current-custodian)
|
(make-servlet (current-custodian)
|
||||||
(current-namespace)
|
(current-namespace)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user