Fixing long standing problem with stateless web apps
This commit is contained in:
parent
202af50a5a
commit
e4a598ccb2
|
@ -25,7 +25,6 @@ These functions optimize the construction of dispatchers and launching of server
|
|||
[#:stateless? stateless? boolean? #f]
|
||||
[#:stuffer stuffer (stuffer/c serializable? bytes?) default-stuffer]
|
||||
[#:manager manager manager? (make-threshold-LRU-manager #f (* 1024 1024 64))]
|
||||
[#:namespace namespace (listof module-path?) empty]
|
||||
[#:current-directory servlet-current-directory path-string? (current-directory)])
|
||||
dispatcher/c]{
|
||||
@racket[serve/servlet] starts a server and uses a particular dispatching sequence. For some applications, this
|
||||
|
@ -41,7 +40,7 @@ These functions optimize the construction of dispatchers and launching of server
|
|||
The servlet is loaded with @racket[manager] as its continuation manager. (The default manager limits the amount of memory to 64 MB and
|
||||
deals with memory pressure as discussed in the @racket[make-threshold-LRU-manager] documentation.)
|
||||
|
||||
The modules specified by @racket[servlet-namespace] are shared with other servlets.
|
||||
The servlet is run in the @racket[(current-namespace)].
|
||||
}
|
||||
|
||||
@defproc[(serve/launch/wait
|
||||
|
|
|
@ -108,8 +108,7 @@ Suppose you would like to start a server for a stateless Web servlet @filepath{s
|
|||
(serve/servlet start #:stateless? #t)
|
||||
]
|
||||
|
||||
@bold{Warning:} If you put the call to @racket[serve/servlet] in a @racketmodname[web-server] module directly it will not work correctly.
|
||||
Consider the following module:
|
||||
You can also put the call to @racket[serve/servlet] in the @racketmodname[web-server] module directly:
|
||||
@racketmod[
|
||||
web-server
|
||||
(require web-server/servlet-env)
|
||||
|
@ -122,11 +121,7 @@ Consider the following module:
|
|||
|
||||
(serve/servlet start #:stateless? #t)
|
||||
]
|
||||
First, if this module is not saved in a file (e.g., @filepath{servlet.rkt}), then the serialization layer cannot locate the definitions of the
|
||||
serialized continuations. Second, due to an unfortunately subtle bug that we have not yet corrected,
|
||||
every time the continuation link is clicked, @racket[serve/servlet] will
|
||||
run and attempt to start a Web server instance and open a browser window. These problems do not occur if your servlet is saved in a file
|
||||
and if @racket[serve/servlet] is run in another module.
|
||||
Like always, you don't even need to save the file.
|
||||
|
||||
@section{Full API}
|
||||
|
||||
|
@ -194,13 +189,13 @@ and if @racket[serve/servlet] is run in another module.
|
|||
as its continuation manager. (The default manager limits the amount of memory to 64 MB and
|
||||
deals with memory pressure as discussed in the @racket[make-threshold-LRU-manager] documentation.)
|
||||
|
||||
The modules specified by @racket[servlet-namespace] are shared with other servlets.
|
||||
|
||||
The server files are rooted at @racket[server-root-path] (which is defaultly the distribution root.)
|
||||
File paths, in addition to the @filepath["htdocs"] directory under @racket[server-root-path] may be
|
||||
provided with @racket[extra-files-paths]. These paths are checked first, in the order they appear in the list.
|
||||
|
||||
Other servlets are served from @racket[servlets-root].
|
||||
Other servlets are served from @racket[servlets-root].
|
||||
The modules specified by @racket[servlet-namespace] are shared between servlets found in @racket[servlets-root] and the current namespace (and therefore
|
||||
the @racket[start] procedure.)
|
||||
|
||||
If a file cannot be found, @racket[file-not-found-responder] is used to generate an error response.
|
||||
|
||||
|
|
|
@ -28,7 +28,6 @@
|
|||
[dispatch/servlet (((request? . -> . response/c))
|
||||
(#:regexp regexp?
|
||||
#:current-directory path-string?
|
||||
#:namespace (listof module-path?)
|
||||
#:stateless? boolean?
|
||||
#:stuffer (stuffer/c serializable? bytes?)
|
||||
#:manager manager?)
|
||||
|
@ -50,9 +49,7 @@
|
|||
#:regexp
|
||||
[servlet-regexp #rx""]
|
||||
#:current-directory
|
||||
[servlet-current-directory (current-directory)]
|
||||
#:namespace
|
||||
[servlet-namespace empty]
|
||||
[servlet-current-directory (current-directory)]
|
||||
#:stateless?
|
||||
[stateless? #f]
|
||||
#:stuffer
|
||||
|
@ -65,8 +62,7 @@
|
|||
(body (p "Sorry, this page has expired. Please go back."))))
|
||||
(* 64 1024 1024))])
|
||||
(define servlet-box (box #f))
|
||||
(define make-servlet-namespace
|
||||
(make-make-servlet-namespace #:to-be-copied-module-specs servlet-namespace))
|
||||
(define namespace-now (current-namespace))
|
||||
(filter:make
|
||||
servlet-regexp
|
||||
(servlets:make
|
||||
|
@ -74,10 +70,7 @@
|
|||
(or (unbox servlet-box)
|
||||
(let ([servlet
|
||||
(parameterize ([current-custodian (make-custodian)]
|
||||
[current-namespace
|
||||
(make-servlet-namespace
|
||||
#:additional-specs
|
||||
default-module-specs)])
|
||||
[current-namespace namespace-now])
|
||||
(if stateless?
|
||||
(make-stateless.servlet servlet-current-directory stuffer manager start)
|
||||
(make-v2.servlet servlet-current-directory manager start)))])
|
||||
|
|
|
@ -148,7 +148,6 @@
|
|||
(dispatch/servlet
|
||||
start
|
||||
#:regexp servlet-regexp
|
||||
#:namespace servlet-namespace
|
||||
#:stateless? stateless?
|
||||
#:stuffer stuffer
|
||||
#:current-directory servlet-current-directory
|
||||
|
|
Loading…
Reference in New Issue
Block a user