Removing old confusion contracts
This commit is contained in:
parent
31f8679e34
commit
c011d611ca
|
@ -1,14 +1,9 @@
|
|||
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?
|
||||
(listof (or/c string? bytes?))) into response data structures for output.
|
||||
conversion of X-expressions and lists with the format (cons/c bytes? (listof (or/c string? bytes?))) into response data structures for output.
|
||||
|
||||
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.
|
||||
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.
|
||||
|
||||
This document describes the incompatible changes and how to restore
|
||||
the old behavior when that is possible.
|
||||
This document describes the incompatible changes and how to restore the old behavior when that is possible.
|
||||
|
||||
--- 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
|
||||
formlets already bake in support for Xexpr as a fundamental part of
|
||||
their syntax.
|
||||
|
||||
|
||||
--- Removed contracts ---
|
||||
|
||||
k-url?
|
||||
response-generator/c
|
||||
expiration-handler/c
|
||||
|
|
30
collects/web-server/compat/0/servlet/servlet-structs.rkt
Normal file
30
collects/web-server/compat/0/servlet/servlet-structs.rkt
Normal 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?])
|
|
@ -24,7 +24,7 @@
|
|||
,@(formlet-display f))))))))
|
||||
|
||||
(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)
|
||||
`(form ([action ,(embed/url
|
||||
|
|
|
@ -36,6 +36,9 @@
|
|||
[initialize-servlet ((request? . -> . response/c) . -> . (request? . -> . response/c))]
|
||||
|
||||
;; 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/url ((url? . -> . response/c) . -> . request?)]
|
||||
[send/suspend/url/dispatch ((((request? . -> . any/c) . -> . url?) . -> . response/c)
|
||||
|
|
|
@ -4,11 +4,20 @@
|
|||
(require "manager.rkt"
|
||||
web-server/servlet/servlet-structs)
|
||||
(provide/contract
|
||||
[create-LRU-manager (expiration-handler/c number? number? (-> boolean?)
|
||||
#:initial-count number?
|
||||
#:inform-p (number? . -> . void)
|
||||
. -> . manager?)]
|
||||
[make-threshold-LRU-manager (expiration-handler/c number? . -> . manager?)])
|
||||
[create-LRU-manager
|
||||
(->
|
||||
(or/c false/c
|
||||
(request? . -> . response/c))
|
||||
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
|
||||
(define (make-counter)
|
||||
|
|
|
@ -16,14 +16,23 @@
|
|||
[struct manager ([create-instance ((-> void) . -> . number?)]
|
||||
[adjust-timeout! (number? 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-peek (number? number? number? . -> . any/c)])]
|
||||
[struct (exn:fail:servlet-manager:no-instance exn:fail)
|
||||
([message string?]
|
||||
[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)
|
||||
([message string?]
|
||||
[continuation-marks continuation-mark-set?]
|
||||
[expiration-handler expiration-handler/c])])
|
||||
[expiration-handler
|
||||
(or/c false/c
|
||||
(request? . -> . response/c))])])
|
||||
|
|
|
@ -3,7 +3,11 @@
|
|||
(require "manager.rkt")
|
||||
(require web-server/servlet/servlet-structs)
|
||||
(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 (create-none-manager
|
||||
|
|
|
@ -5,7 +5,12 @@
|
|||
(require web-server/private/timer
|
||||
web-server/servlet/servlet-structs)
|
||||
(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
|
||||
(define (make-counter)
|
||||
|
|
|
@ -22,39 +22,4 @@ This allows Web applications to customize the Web Server's handling of responses
|
|||
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.
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -450,7 +450,7 @@ A few utilities are provided for using @tech{formlet}s in Web applications.
|
|||
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 ...)])
|
||||
xexpr/c]{
|
||||
Like @racket[send/formlet], but for use with @racket[send/suspend/dispatch].
|
||||
|
|
|
@ -23,7 +23,10 @@ the users and implementers of managers.
|
|||
@defstruct[manager ([create-instance ((-> void) . -> . number?)]
|
||||
[adjust-timeout! (number? 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-peek (number? number? number? . -> . any/c)])]{
|
||||
@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)
|
||||
([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
|
||||
up that does not exist.
|
||||
}
|
||||
|
||||
@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
|
||||
looked up that does not exist.
|
||||
}
|
||||
|
@ -72,7 +79,10 @@ the users and implementers of managers.
|
|||
|
||||
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?]{
|
||||
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
|
||||
|
@ -97,9 +107,12 @@ Web Language. (See @secref["stateless"].)
|
|||
|
||||
This module defines a manager constructor:
|
||||
|
||||
@defproc[(create-timeout-manager [instance-exp-handler expiration-handler/c]
|
||||
[instance-timeout number?]
|
||||
[continuation-timeout number?])
|
||||
@defproc[(create-timeout-manager
|
||||
[instance-exp-handler
|
||||
(or/c false/c
|
||||
(request? . -> . response/c))]
|
||||
[instance-timeout number?]
|
||||
[continuation-timeout number?])
|
||||
manager?]{
|
||||
Instances managed by this manager will be expired @racket[instance-timeout]
|
||||
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:
|
||||
|
||||
@defproc[(create-LRU-manager
|
||||
[instance-expiration-handler expiration-handler/c]
|
||||
[instance-expiration-handler
|
||||
(or/c false/c
|
||||
(request? . -> . response/c))]
|
||||
[check-interval integer?]
|
||||
[collect-interval integer?]
|
||||
[collect? (-> boolean?)]
|
||||
|
@ -163,7 +178,9 @@ This module defines a manager constructor:
|
|||
The recommended usage of this manager is codified as the following function:
|
||||
|
||||
@defproc[(make-threshold-LRU-manager
|
||||
[instance-expiration-handler expiration-handler/c]
|
||||
[instance-expiration-handler
|
||||
(or/c false/c
|
||||
(request? . -> . response/c))]
|
||||
[memory-threshold number?])
|
||||
manager?]{
|
||||
This creates an LRU manager with the following behavior:
|
||||
|
|
|
@ -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.
|
||||
}
|
||||
|
||||
@defthing[current-servlet-continuation-expiration-handler (parameter/c expiration-handler/c)]{
|
||||
Holds the @racket[expiration-handler/c] to be used when a continuation
|
||||
@defthing[current-servlet-continuation-expiration-handler
|
||||
(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.
|
||||
|
||||
Example:
|
||||
|
|
|
@ -8,23 +8,6 @@
|
|||
(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?])
|
||||
[response/c contract?])
|
||||
|
|
|
@ -36,16 +36,19 @@
|
|||
;; ********************************************************************************
|
||||
|
||||
(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/forget (() (#:headers (listof header?)) . ->* . request?)]
|
||||
[adjust-timeout! (number? . -> . void?)]
|
||||
[clear-continuation-table! (-> void?)]
|
||||
[send/back (response/c . -> . void?)]
|
||||
[send/finish (response/c . -> . void?)]
|
||||
[send/forward (response-generator/c . -> . request?)]
|
||||
[send/suspend (response-generator/c . -> . request?)]
|
||||
[send/suspend/dispatch ((embed/url/c . -> . response/c) . -> . any/c)]
|
||||
[send/forward ((string? . -> . response/c) . -> . request?)]
|
||||
[send/suspend ((string? . -> . response/c) . -> . request?)]
|
||||
[send/suspend/dispatch ((((request? . -> . any) . -> . string?) . -> . response/c) . -> . any/c)]
|
||||
[send/suspend/url ((url? . -> . response/c) . -> . request?)]
|
||||
[send/suspend/url/dispatch ((((request? . -> . any/c) . -> . url?) . -> . response/c) . -> . any/c)])
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user