Removing old confusion contracts

This commit is contained in:
Jay McCarthy 2010-12-07 12:55:13 -07:00
parent 31f8679e34
commit c011d611ca
14 changed files with 120 additions and 88 deletions

View File

@ -1,14 +1,9 @@
In Racket 5.0.99.4 and before, the Web Server supported implicit In Racket 5.0.99.4 and before, the Web Server supported implicit
conversion of X-expressions and lists with the format (cons/c bytes? conversion of X-expressions and lists with the format (cons/c bytes? (listof (or/c string? bytes?))) into response data structures for output.
(listof (or/c string? bytes?))) into response data structures for output.
After 5.0.99.4, this implicit conversion has been generalized into After 5.0.99.4, this implicit conversion has been generalized into current-response/c and response/c. In the process, implicit conversion has been completely removed from some internal plumbing AND the response structures have been streamlined---primarily for efficiency.
current-response/c and response/c. In the process, implicit conversion
has been completely removed from some internal plumbing AND the
response structures have been streamlined---primarily for efficiency.
This document describes the incompatible changes and how to restore This document describes the incompatible changes and how to restore the old behavior when that is possible.
the old behavior when that is possible.
--- Coercion behavior --- --- Coercion behavior ---
@ -75,3 +70,10 @@ old response/c as a wrapper result, while the new version requires
that the wrapper returns an Xexpr. This changes is justified in that that the wrapper returns an Xexpr. This changes is justified in that
formlets already bake in support for Xexpr as a fundamental part of formlets already bake in support for Xexpr as a fundamental part of
their syntax. their syntax.
--- Removed contracts ---
k-url?
response-generator/c
expiration-handler/c

View File

@ -0,0 +1,30 @@
#lang racket/base
(require racket/contract
unstable/contract
web-server/http)
(define current-response/c
(make-parameter any/c))
(define response/c
(dynamic/c any/c current-response/c response?))
(define k-url?
string?)
(define response-generator/c
(k-url? . -> . response/c))
(define expiration-handler/c
(or/c false/c
(request? . -> . response/c)))
(define embed/url/c
((request? . -> . any) . -> . string?))
(provide/contract
[current-response/c (parameter/c contract?)]
[response/c contract?]
[response-generator/c contract?]
[k-url? contract?]
[expiration-handler/c contract?]
[embed/url/c contract?])

View File

@ -24,7 +24,7 @@
,@(formlet-display f)))))))) ,@(formlet-display f))))))))
(provide/contract (provide/contract
[embed-formlet (embed/url/c formlet*/c . -> . pretty-xexpr/c)]) [embed-formlet (((request? . -> . any) . -> . string?) formlet*/c . -> . pretty-xexpr/c)])
(define (embed-formlet embed/url f) (define (embed-formlet embed/url f)
`(form ([action ,(embed/url `(form ([action ,(embed/url

View File

@ -36,6 +36,9 @@
[initialize-servlet ((request? . -> . response/c) . -> . (request? . -> . response/c))] [initialize-servlet ((request? . -> . response/c) . -> . (request? . -> . response/c))]
;; Servlet Interface ;; Servlet Interface
[send/suspend ((string? . -> . response/c) . -> . request?)]
[send/suspend/dispatch ((((request? . -> . any/c) . -> . string?) . -> . response/c)
. -> . any/c)]
[send/suspend/hidden ((url? list? . -> . response/c) . -> . request?)] [send/suspend/hidden ((url? list? . -> . response/c) . -> . request?)]
[send/suspend/url ((url? . -> . response/c) . -> . request?)] [send/suspend/url ((url? . -> . response/c) . -> . request?)]
[send/suspend/url/dispatch ((((request? . -> . any/c) . -> . url?) . -> . response/c) [send/suspend/url/dispatch ((((request? . -> . any/c) . -> . url?) . -> . response/c)

View File

@ -4,11 +4,20 @@
(require "manager.rkt" (require "manager.rkt"
web-server/servlet/servlet-structs) web-server/servlet/servlet-structs)
(provide/contract (provide/contract
[create-LRU-manager (expiration-handler/c number? number? (-> boolean?) [create-LRU-manager
#:initial-count number? (->
#:inform-p (number? . -> . void) (or/c false/c
. -> . manager?)] (request? . -> . response/c))
[make-threshold-LRU-manager (expiration-handler/c number? . -> . manager?)]) number? number? (-> boolean?)
#:initial-count number?
#:inform-p (number? . -> . void)
manager?)]
[make-threshold-LRU-manager
(->
(or/c false/c
(request? . -> . response/c))
number?
manager?)])
;; Utility ;; Utility
(define (make-counter) (define (make-counter)

View File

@ -16,14 +16,23 @@
[struct manager ([create-instance ((-> void) . -> . number?)] [struct manager ([create-instance ((-> void) . -> . number?)]
[adjust-timeout! (number? number? . -> . void)] [adjust-timeout! (number? number? . -> . void)]
[clear-continuations! (number? . -> . void)] [clear-continuations! (number? . -> . void)]
[continuation-store! (number? any/c expiration-handler/c . -> . (list/c number? number?))] [continuation-store!
(->
number? any/c
(or/c false/c
(request? . -> . response/c))
(list/c number? number?))]
[continuation-lookup (number? number? number? . -> . any/c)] [continuation-lookup (number? number? number? . -> . any/c)]
[continuation-peek (number? number? number? . -> . any/c)])] [continuation-peek (number? number? number? . -> . any/c)])]
[struct (exn:fail:servlet-manager:no-instance exn:fail) [struct (exn:fail:servlet-manager:no-instance exn:fail)
([message string?] ([message string?]
[continuation-marks continuation-mark-set?] [continuation-marks continuation-mark-set?]
[expiration-handler expiration-handler/c])] [expiration-handler
(or/c false/c
(request? . -> . response/c))])]
[struct (exn:fail:servlet-manager:no-continuation exn:fail) [struct (exn:fail:servlet-manager:no-continuation exn:fail)
([message string?] ([message string?]
[continuation-marks continuation-mark-set?] [continuation-marks continuation-mark-set?]
[expiration-handler expiration-handler/c])]) [expiration-handler
(or/c false/c
(request? . -> . response/c))])])

View File

@ -3,7 +3,11 @@
(require "manager.rkt") (require "manager.rkt")
(require web-server/servlet/servlet-structs) (require web-server/servlet/servlet-structs)
(provide/contract (provide/contract
[create-none-manager (expiration-handler/c . -> . manager?)]) [create-none-manager
(->
(or/c false/c
(request? . -> . response/c))
manager?)])
(define-struct (none-manager manager) (instance-expiration-handler)) (define-struct (none-manager manager) (instance-expiration-handler))
(define (create-none-manager (define (create-none-manager

View File

@ -5,7 +5,12 @@
(require web-server/private/timer (require web-server/private/timer
web-server/servlet/servlet-structs) web-server/servlet/servlet-structs)
(provide/contract (provide/contract
[create-timeout-manager (expiration-handler/c number? number? . -> . manager?)]) [create-timeout-manager
(->
(or/c false/c
(request? . -> . response/c))
number? number?
manager?)])
;; Utility ;; Utility
(define (make-counter) (define (make-counter)

View File

@ -22,39 +22,4 @@ This allows Web applications to customize the Web Server's handling of responses
always receives @racket[response?] structures. always receives @racket[response?] structures.
} }
@defthing[k-url? contract?]{
Equivalent to @racket[string?].
Example: @racket["http://localhost:8080/servlets;1*1*20131636/examples/add.rkt"]}
@defthing[response-generator/c contract?]{
Equivalent to @racket[(k-url? . -> . response/c)].
Example: @racketblock[(lambda (k-url)
(response/xexpr
`(html
(body
(a ([href ,k-url])
"Click Me to Invoke the Continuation!")))))]
}
@defthing[expiration-handler/c contract?]{
Equivalent to @racket[(or/c false/c (request? . -> . response/c))].
Typically @racket[#f] uses the default expiration handler, which displays an error message.
Example: @racketblock[(lambda (req)
(response/xexpr
`(html (head (title "Expired"))
(body (h1 "Expired")
(p "This URL has expired. "
"Please return to the home page.")))))]
}
@defthing[embed/url/c contract?]{
Equivalent to @racket[((request? . -> . any) . -> . string?)].
This is what @racket[send/suspend/dispatch] gives to its function argument.
}
} }

View File

@ -450,7 +450,7 @@ A few utilities are provided for using @tech{formlet}s in Web applications.
processing stage of @racket[f]. processing stage of @racket[f].
} }
@defproc[(embed-formlet [embed/url embed/url/c] @defproc[(embed-formlet [embed/url ((request? . -> . any) . -> . string?)]
[f (formlet/c any/c ...)]) [f (formlet/c any/c ...)])
xexpr/c]{ xexpr/c]{
Like @racket[send/formlet], but for use with @racket[send/suspend/dispatch]. Like @racket[send/formlet], but for use with @racket[send/suspend/dispatch].

View File

@ -23,7 +23,10 @@ the users and implementers of managers.
@defstruct[manager ([create-instance ((-> void) . -> . number?)] @defstruct[manager ([create-instance ((-> void) . -> . number?)]
[adjust-timeout! (number? number? . -> . void)] [adjust-timeout! (number? number? . -> . void)]
[clear-continuations! (number? . -> . void)] [clear-continuations! (number? . -> . void)]
[continuation-store! (number? any/c expiration-handler/c . -> . (list/c number? number?))] [continuation-store! (number? any/c
(or/c false/c
(request? . -> . response/c))
. -> . (list/c number? number?))]
[continuation-lookup (number? number? number? . -> . any/c)] [continuation-lookup (number? number? number? . -> . any/c)]
[continuation-peek (number? number? number? . -> . any/c)])]{ [continuation-peek (number? number? number? . -> . any/c)])]{
@racket[create-instance] is called to initialize a instance, to hold the @racket[create-instance] is called to initialize a instance, to hold the
@ -51,13 +54,17 @@ the users and implementers of managers.
} }
@defstruct[(exn:fail:servlet-manager:no-instance exn:fail) @defstruct[(exn:fail:servlet-manager:no-instance exn:fail)
([expiration-handler expiration-handler/c])]{ ([expiration-handler
(or/c false/c
(request? . -> . response/c))])]{
This exception should be thrown by a manager when an instance is looked This exception should be thrown by a manager when an instance is looked
up that does not exist. up that does not exist.
} }
@defstruct[(exn:fail:servlet-manager:no-continuation exn:fail) @defstruct[(exn:fail:servlet-manager:no-continuation exn:fail)
([expiration-handler expiration-handler/c])]{ ([expiration-handler
(or/c false/c
(request? . -> . response/c))])]{
This exception should be thrown by a manager when a continuation is This exception should be thrown by a manager when a continuation is
looked up that does not exist. looked up that does not exist.
} }
@ -72,7 +79,10 @@ the users and implementers of managers.
This module defines a manager constructor: This module defines a manager constructor:
@defproc[(create-none-manager (instance-expiration-handler expiration-handler/c)) @defproc[(create-none-manager
(instance-expiration-handler
(or/c false/c
(request? . -> . response/c))))
manager?]{ manager?]{
This manager does not actually store any continuation or instance data. This manager does not actually store any continuation or instance data.
You could use it if you know your servlet does not use the continuation You could use it if you know your servlet does not use the continuation
@ -97,9 +107,12 @@ Web Language. (See @secref["stateless"].)
This module defines a manager constructor: This module defines a manager constructor:
@defproc[(create-timeout-manager [instance-exp-handler expiration-handler/c] @defproc[(create-timeout-manager
[instance-timeout number?] [instance-exp-handler
[continuation-timeout number?]) (or/c false/c
(request? . -> . response/c))]
[instance-timeout number?]
[continuation-timeout number?])
manager?]{ manager?]{
Instances managed by this manager will be expired @racket[instance-timeout] Instances managed by this manager will be expired @racket[instance-timeout]
seconds after the last time it is accessed. If an expired instance is seconds after the last time it is accessed. If an expired instance is
@ -130,7 +143,9 @@ deployments of the @web-server .
This module defines a manager constructor: This module defines a manager constructor:
@defproc[(create-LRU-manager @defproc[(create-LRU-manager
[instance-expiration-handler expiration-handler/c] [instance-expiration-handler
(or/c false/c
(request? . -> . response/c))]
[check-interval integer?] [check-interval integer?]
[collect-interval integer?] [collect-interval integer?]
[collect? (-> boolean?)] [collect? (-> boolean?)]
@ -163,7 +178,9 @@ This module defines a manager constructor:
The recommended usage of this manager is codified as the following function: The recommended usage of this manager is codified as the following function:
@defproc[(make-threshold-LRU-manager @defproc[(make-threshold-LRU-manager
[instance-expiration-handler expiration-handler/c] [instance-expiration-handler
(or/c false/c
(request? . -> . response/c))]
[memory-threshold number?]) [memory-threshold number?])
manager?]{ manager?]{
This creates an LRU manager with the following behavior: This creates an LRU manager with the following behavior:

View File

@ -160,8 +160,10 @@ functions of interest for the servlet developer.
Calls @racket[send/forward] with @racket[redirect-to], passing @racket[hs] as the headers. Calls @racket[send/forward] with @racket[redirect-to], passing @racket[hs] as the headers.
} }
@defthing[current-servlet-continuation-expiration-handler (parameter/c expiration-handler/c)]{ @defthing[current-servlet-continuation-expiration-handler
Holds the @racket[expiration-handler/c] to be used when a continuation (parameter/c (or/c false/c
(request? . -> . response/c)))]{
Holds the expiration handler to be used when a continuation
captured in this context is expired, then looked up. captured in this context is expired, then looked up.
Example: Example:

View File

@ -8,23 +8,6 @@
(define response/c (define response/c
(dynamic/c any/c current-response/c response?)) (dynamic/c any/c current-response/c response?))
(define k-url?
string?)
(define response-generator/c
(k-url? . -> . response/c))
(define expiration-handler/c
(or/c false/c
(request? . -> . response/c)))
(define embed/url/c
((request? . -> . any) . -> . string?))
(provide/contract (provide/contract
[current-response/c (parameter/c contract?)] [current-response/c (parameter/c contract?)]
[response/c contract?] [response/c contract?])
[response-generator/c contract?]
[k-url? contract?]
[expiration-handler/c contract?]
[embed/url/c contract?])

View File

@ -36,16 +36,19 @@
;; ******************************************************************************** ;; ********************************************************************************
(provide/contract (provide/contract
[current-servlet-continuation-expiration-handler (parameter/c expiration-handler/c)] [current-servlet-continuation-expiration-handler
(parameter/c
(or/c false/c
(request? . -> . response/c)))]
[redirect/get (() (#:headers (listof header?)) . ->* . request?)] [redirect/get (() (#:headers (listof header?)) . ->* . request?)]
[redirect/get/forget (() (#:headers (listof header?)) . ->* . request?)] [redirect/get/forget (() (#:headers (listof header?)) . ->* . request?)]
[adjust-timeout! (number? . -> . void?)] [adjust-timeout! (number? . -> . void?)]
[clear-continuation-table! (-> void?)] [clear-continuation-table! (-> void?)]
[send/back (response/c . -> . void?)] [send/back (response/c . -> . void?)]
[send/finish (response/c . -> . void?)] [send/finish (response/c . -> . void?)]
[send/forward (response-generator/c . -> . request?)] [send/forward ((string? . -> . response/c) . -> . request?)]
[send/suspend (response-generator/c . -> . request?)] [send/suspend ((string? . -> . response/c) . -> . request?)]
[send/suspend/dispatch ((embed/url/c . -> . response/c) . -> . any/c)] [send/suspend/dispatch ((((request? . -> . any) . -> . string?) . -> . response/c) . -> . any/c)]
[send/suspend/url ((url? . -> . response/c) . -> . request?)] [send/suspend/url ((url? . -> . response/c) . -> . request?)]
[send/suspend/url/dispatch ((((request? . -> . any/c) . -> . url?) . -> . response/c) . -> . any/c)]) [send/suspend/url/dispatch ((((request? . -> . any/c) . -> . url?) . -> . response/c) . -> . any/c)])