From d085b21a90cd5c3055983cbd81cbfcdf43682947 Mon Sep 17 00:00:00 2001 From: Jay McCarthy Date: Tue, 18 Nov 2008 17:53:18 +0000 Subject: [PATCH] Clarifying manager docs and adding interface to serve/servlets svn: r12494 --- .../web-server/scribblings/managers.scrbl | 2 +- .../web-server/scribblings/servlet-env.scrbl | 54 +++++++++++-------- collects/web-server/servlet-env.ss | 52 ++++++++++-------- 3 files changed, 64 insertions(+), 44 deletions(-) diff --git a/collects/web-server/scribblings/managers.scrbl b/collects/web-server/scribblings/managers.scrbl index 24ceb3a4a5..834fee6636 100644 --- a/collects/web-server/scribblings/managers.scrbl +++ b/collects/web-server/scribblings/managers.scrbl @@ -165,7 +165,7 @@ The recommended usage of this manager is codified as the following function: [memory-threshold number?]) manager?]{ This creates an LRU manager with the following behavior: - The memory limit is set to @scheme[memory-threshold]. Continuations start with @scheme[24] + The memory limit is set to @scheme[memory-threshold] bytes. Continuations start with @scheme[24] life points. Life points are deducted at the rate of one every @scheme[10] minutes, or one every @scheme[5] seconds when the memory limit is exceeded. Hence the maximum life time for a continuation is @scheme[4] hours, and the minimum is @scheme[2] minutes. diff --git a/collects/web-server/scribblings/servlet-env.scrbl b/collects/web-server/scribblings/servlet-env.scrbl index bc8e7d94dc..7b93592f84 100644 --- a/collects/web-server/scribblings/servlet-env.scrbl +++ b/collects/web-server/scribblings/servlet-env.scrbl @@ -6,6 +6,7 @@ @(require (for-label web-server/servlet-env web-server/http web-server/managers/lru + web-server/configuration/responders scheme/list)) @defmodule[web-server/servlet-env]{ @@ -70,26 +71,34 @@ Suppose you would like to start a server for a stateless Web servlet @filepath{s Note: If you put the call to @scheme[serve/servlet] in the module like normal, strange things will happen because of the way the top-level interacts with continuations. (Read: Don't do it.) +If you want to use @scheme[serve/servlet] in a start up script for a Web server, and don't want a browser opened or the DrScheme banner printed, then you can write: +@schemeblock[ +(serve/servlet my-app + #:command-line? #t) +] + @defproc[(serve/servlet [start (request? . -> . response?)] - [#:launch-browser? launch-browser? boolean? #t] - [#:quit? quit? boolean? #t] - [#:listen-ip listen-ip string? "127.0.0.1"] - [#:port port number? 8000] - [#:servlet-path servlet-path string? - "/servlets/standalone.ss"] - [#:servlet-regexp servlet-regexp regexp? - (regexp (format "^~a$" (regexp-quote servlet-path)))] - [#:stateless? stateless? boolean? #f] - [#:manager manager manager? (make-threshold-LRU-manager #f (* 1024 1024 64))] - [#:servlet-namespace servlet-namespace (listof module-path?) empty] - [#:server-root-path server-root-path path? default-server-root-path] - [#:extra-files-paths extra-files-paths (listof path?) (list (build-path server-root-path "htdocs"))] - [#:servlets-root servlets-root path? (build-path server-root-path "htdocs")] - [#:servlet-current-directory servlet-current-directory path? servlets-root] - [#:file-not-found-path file-not-found-path path? - (build-path server-root-path "conf" "not-found.html")] - [#:mime-types-path mime-types-path path? - (build-path server-root-path "mime.types")]) + [#:command-line? command-line? boolean? #f] + [#:launch-browser? launch-browser? boolean? (not command-line?)] + [#:quit? quit? boolean? (not command-line?)] + [#:banner? banner? boolean? (not command-line?)] + [#:listen-ip listen-ip string? "127.0.0.1"] + [#:port port number? 8000] + [#:servlet-path servlet-path string? + "/servlets/standalone.ss"] + [#:servlet-regexp servlet-regexp regexp? + (regexp (format "^~a$" (regexp-quote servlet-path)))] + [#:stateless? stateless? boolean? #f] + [#:manager manager manager? (make-threshold-LRU-manager #f (* 1024 1024 64))] + [#:servlet-namespace servlet-namespace (listof module-path?) empty] + [#:server-root-path server-root-path path? default-server-root-path] + [#:extra-files-paths extra-files-paths (listof path?) (list (build-path server-root-path "htdocs"))] + [#:servlets-root servlets-root path? (build-path server-root-path "htdocs")] + [#:servlet-current-directory servlet-current-directory path? servlets-root] + [#:file-not-found-responder file-not-found-responder + (gen-file-not-found-responder (build-path server-root-path "conf" "not-found.html"))] + [#:mime-types-path mime-types-path path? + (build-path server-root-path "mime.types")]) void]{ This sets up and starts a fairly default server instance. @@ -99,7 +108,7 @@ the top-level interacts with continuations. (Read: Don't do it.) If @scheme[launch-browser?] is true, then a web browser is opened to @filepath{http://localhost:}. If @scheme[quit?] is true, then the URL @filepath["/quit"] ends the server. - + If @scheme[stateless?] is true, then the servlet is run as a stateless @schememodname[web-server] module. Advanced users may need the following options: @@ -118,7 +127,10 @@ the top-level interacts with continuations. (Read: Don't do it.) Other servlets are served from @scheme[servlets-root]. - If a file cannot be found, @scheme[file-not-found-path] is used as an error response. + If a file cannot be found, @scheme[file-not-found-responder] is used to generate an error response. + + If @scheme[banner?] is true, then an informative banner is printed. You may want to use this when + running from the command line, in which case the @scheme[command-line?] option controls similar options. MIME types are looked up at @scheme[mime-types-path]. } diff --git a/collects/web-server/servlet-env.ss b/collects/web-server/servlet-env.ss index d9b90ecc61..e6988ba34d 100644 --- a/collects/web-server/servlet-env.ss +++ b/collects/web-server/servlet-env.ss @@ -41,27 +41,33 @@ (provide/contract [serve/servlet (((request? . -> . response?)) - (#:launch-browser? boolean? - #:quit? boolean? - #:listen-ip string? - #:port number? - #:manager manager? - #:servlet-namespace (listof module-path?) - #:server-root-path path? - #:stateless? boolean? - #:extra-files-paths (listof path?) - #:servlets-root path? - #:file-not-found-path path? - #:mime-types-path path? - #:servlet-path string? - #:servlet-regexp regexp?) + (#:command-line? boolean? + #:launch-browser? boolean? + #:quit? boolean? + #:banner? boolean? + #:listen-ip string? + #:port number? + #:manager manager? + #:servlet-namespace (listof module-path?) + #:server-root-path path? + #:stateless? boolean? + #:extra-files-paths (listof path?) + #:servlets-root path? + #:file-not-found-responder (request? . -> . response?) + #:mime-types-path path? + #:servlet-path string? + #:servlet-regexp regexp?) . ->* . void)]) (define (serve/servlet start + #:command-line? + [command-line? #f] #:launch-browser? - [launch-browser? #t] + [launch-browser? (not command-line?)] #:quit? - [quit? #t] + [quit? (not command-line?)] + #:banner? + [banner? (not command-line?)] #:listen-ip [listen-ip "127.0.0.1"] @@ -93,8 +99,8 @@ [servlets-root (build-path server-root-path "htdocs")] #:servlet-current-directory [servlet-current-directory servlets-root] - #:file-not-found-path - [file-not-found-path (build-path server-root-path "conf" "not-found.html")] + #:file-not-found-responder + [file-not-found-responder (gen-file-not-found-responder (build-path server-root-path "conf" "not-found.html"))] #:mime-types-path [mime-types-path (build-path server-root-path "mime.types")]) (define standalone-url @@ -149,19 +155,21 @@ (build-path server-root-path "htdocs")) #:path->mime-type (make-path->mime-type (build-path server-root-path "mime.types")) #:indices (list "index.html" "index.htm")) - (lift:make (gen-file-not-found-responder file-not-found-path)))) + (lift:make file-not-found-responder))) (define shutdown-server (serve #:dispatch dispatcher #:listen-ip listen-ip #:port the-port)) (when launch-browser? ((send-url) standalone-url #t)) - (printf "Your Web application is running at ~a.~n" standalone-url) - (printf "Click 'Stop' at any time to terminate the Web Server.~n") + (when banner? + (printf "Your Web application is running at ~a.~n" standalone-url) + (printf "Click 'Stop' at any time to terminate the Web Server.~n")) (with-handlers ([exn:break? (lambda (exn) - (printf "~nWeb Server stopped.~n") + (when banner? + (printf "~nWeb Server stopped.~n")) (shutdown-server))]) (semaphore-wait/enable-break sema)) ; We shouldn't get here, because nothing posts to the semaphore. But just in case...