Removing send/suspend/callback
svn: r6628
This commit is contained in:
parent
2b84dcf7f6
commit
aa2a889a18
|
@ -1,26 +0,0 @@
|
||||||
(module add-call mzscheme
|
|
||||||
(require (lib "servlet.ss" "web-server"))
|
|
||||||
(provide (all-defined))
|
|
||||||
(define interface-version 'v1)
|
|
||||||
(define timeout +inf.0)
|
|
||||||
|
|
||||||
; request-number : str -> num
|
|
||||||
(define (request-number which-number)
|
|
||||||
(send/suspend/callback
|
|
||||||
`(html (head (title "Enter a Number to Add"))
|
|
||||||
(body ([bgcolor "white"])
|
|
||||||
(form ([action ,(lambda (request)
|
|
||||||
(string->number
|
|
||||||
(extract-binding/single
|
|
||||||
'number
|
|
||||||
(request-bindings request))))]
|
|
||||||
[method "post"])
|
|
||||||
"Enter the " ,which-number " number to add: "
|
|
||||||
(input ([type "text"] [name "number"] [value ""]))
|
|
||||||
(input ([type "submit"] [name "enter"] [value "Enter"])))))))
|
|
||||||
|
|
||||||
(define (start initial-request)
|
|
||||||
`(html (head (title "Sum"))
|
|
||||||
(body ([bgcolor "white"])
|
|
||||||
(p "The sum is "
|
|
||||||
,(number->string (+ (request-number "first") (request-number "second"))))))))
|
|
|
@ -56,12 +56,6 @@ provides:
|
||||||
for use in servlets.
|
for use in servlets.
|
||||||
|
|
||||||
@defthing[servlet-response? contract?]{Equivalent to @scheme[any/c].}
|
@defthing[servlet-response? contract?]{Equivalent to @scheme[any/c].}
|
||||||
|
|
||||||
@; XXX Remove callbacks
|
|
||||||
@defthing[xexpr/callback? contract?]{
|
|
||||||
Checks if the value matches @scheme[xexpr?], except that embedded
|
|
||||||
procedures are allowed.
|
|
||||||
}
|
|
||||||
|
|
||||||
@defthing[k-url? contract?]{Equivalent to @scheme[string?].}
|
@defthing[k-url? contract?]{Equivalent to @scheme[string?].}
|
||||||
|
|
||||||
|
@ -282,18 +276,6 @@ servlet developer.
|
||||||
@scheme[send/suspend/dispatch].
|
@scheme[send/suspend/dispatch].
|
||||||
}
|
}
|
||||||
|
|
||||||
@; XXX Remove
|
|
||||||
@defproc[(xexpr/callback->xexpr [embed/url embed/url?]
|
|
||||||
[xexpr/c xexpr/callback?])
|
|
||||||
xexpr?]{
|
|
||||||
Replaces the procedures in @scheme[xexpr/c] with URLs through @scheme[embed/url].
|
|
||||||
}
|
|
||||||
|
|
||||||
@defproc[(send/suspend/callback [xexpr/c xexpr/callback?])
|
|
||||||
any/c]{
|
|
||||||
Calls @scheme[send/suspend/dispatch] and @scheme[xexpr/callback->xexpr].
|
|
||||||
}
|
|
||||||
|
|
||||||
@defproc[(redirect/get)
|
@defproc[(redirect/get)
|
||||||
request?]{
|
request?]{
|
||||||
Calls @scheme[send/suspend] with @scheme[redirect-to].
|
Calls @scheme[send/suspend] with @scheme[redirect-to].
|
||||||
|
|
|
@ -6,16 +6,7 @@
|
||||||
|
|
||||||
(define servlet-response?
|
(define servlet-response?
|
||||||
any/c)
|
any/c)
|
||||||
|
|
||||||
(define (xexpr/callback? x)
|
|
||||||
(correct-xexpr? x
|
|
||||||
(lambda () #t)
|
|
||||||
(lambda (exn)
|
|
||||||
(if (procedure? (exn:invalid-xexpr-code exn))
|
|
||||||
#t
|
|
||||||
(begin ((error-display-handler) (exn-message exn) exn)
|
|
||||||
#f)))))
|
|
||||||
|
|
||||||
(define k-url?
|
(define k-url?
|
||||||
string?)
|
string?)
|
||||||
|
|
||||||
|
@ -34,7 +25,6 @@
|
||||||
|
|
||||||
(provide/contract
|
(provide/contract
|
||||||
[servlet-response? contract?]
|
[servlet-response? contract?]
|
||||||
[xexpr/callback? (any/c . -> . boolean?)]
|
|
||||||
[response-generator? contract?]
|
[response-generator? contract?]
|
||||||
[k-url? (any/c . -> . boolean?)]
|
[k-url? (any/c . -> . boolean?)]
|
||||||
[url-transform? contract?]
|
[url-transform? contract?]
|
||||||
|
|
|
@ -65,21 +65,11 @@
|
||||||
(list* (make-path/param (path/param-path (first old-path))
|
(list* (make-path/param (path/param-path (first old-path))
|
||||||
(list new-param-str))
|
(list new-param-str))
|
||||||
(rest old-path))))
|
(rest old-path))))
|
||||||
in-url)))
|
in-url)))
|
||||||
|
|
||||||
;; replace-procedures : (proc -> url) xexpr/callbacks? -> xexpr?
|
|
||||||
;; Change procedures to the send/suspend of a k-url
|
|
||||||
(define (xexpr/callback->xexpr p->a p-exp)
|
|
||||||
(cond
|
|
||||||
[(list? p-exp) (map (lambda (p-e) (xexpr/callback->xexpr p->a p-e))
|
|
||||||
p-exp)]
|
|
||||||
[(procedure? p-exp) (p->a p-exp)]
|
|
||||||
[else p-exp]))
|
|
||||||
|
|
||||||
;; XXX Weak contracts: the input is checked in output-response, and a message is
|
;; XXX Weak contracts: the input is checked in output-response, and a message is
|
||||||
;; sent directly to the client (Web browser) instead of the terminal/log.
|
;; sent directly to the client (Web browser) instead of the terminal/log.
|
||||||
(provide/contract
|
(provide/contract
|
||||||
[xexpr/callback->xexpr (embed/url? xexpr/callback? . -> . xexpr?)]
|
|
||||||
[current-url-transform parameter?]
|
[current-url-transform parameter?]
|
||||||
[current-servlet-continuation-expiration-handler parameter?]
|
[current-servlet-continuation-expiration-handler parameter?]
|
||||||
[redirect/get (-> request?)]
|
[redirect/get (-> request?)]
|
||||||
|
@ -90,8 +80,7 @@
|
||||||
[send/finish (any/c . -> . void?)]
|
[send/finish (any/c . -> . void?)]
|
||||||
[send/suspend ((response-generator?) (expiration-handler?) . opt-> . request?)]
|
[send/suspend ((response-generator?) (expiration-handler?) . opt-> . request?)]
|
||||||
[send/forward ((response-generator?) (expiration-handler?) . opt-> . request?)]
|
[send/forward ((response-generator?) (expiration-handler?) . opt-> . request?)]
|
||||||
[send/suspend/dispatch ((embed/url? . -> . servlet-response?) . -> . any/c)]
|
[send/suspend/dispatch ((embed/url? . -> . servlet-response?) . -> . any/c)])
|
||||||
[send/suspend/callback (xexpr/callback? . -> . any/c)])
|
|
||||||
|
|
||||||
;; ************************************************************
|
;; ************************************************************
|
||||||
;; EXPORTS
|
;; EXPORTS
|
||||||
|
@ -176,14 +165,7 @@
|
||||||
(k0 (lambda () (proc new-request)))))))))
|
(k0 (lambda () (proc new-request)))))))))
|
||||||
servlet-prompt)])
|
servlet-prompt)])
|
||||||
(thunk)))
|
(thunk)))
|
||||||
|
|
||||||
;; send/suspend/callback : xexpr/callback? -> void
|
|
||||||
;; send/back a response with callbacks in it; send/suspend those callbacks.
|
|
||||||
(define (send/suspend/callback p-exp)
|
|
||||||
(send/suspend/dispatch
|
|
||||||
(lambda (embed/url)
|
|
||||||
(xexpr/callback->xexpr embed/url p-exp))))
|
|
||||||
|
|
||||||
;; ************************************************************
|
;; ************************************************************
|
||||||
;; HIGHER-LEVEL EXPORTS
|
;; HIGHER-LEVEL EXPORTS
|
||||||
|
|
||||||
|
|
|
@ -72,8 +72,6 @@
|
||||||
(build-path example-servlets "add-v2.ss"))
|
(build-path example-servlets "add-v2.ss"))
|
||||||
(test-add-two-numbers "add-ssd.ss - send/suspend/dispatch"
|
(test-add-two-numbers "add-ssd.ss - send/suspend/dispatch"
|
||||||
(build-path example-servlets "add-ssd.ss"))
|
(build-path example-servlets "add-ssd.ss"))
|
||||||
(test-add-two-numbers "add-call.ss - send/suspend/callback"
|
|
||||||
(build-path example-servlets "add-call.ss"))
|
|
||||||
(test-equal? "count.ss - state"
|
(test-equal? "count.ss - state"
|
||||||
(let* ([d (mkd (build-path example-servlets "count.ss"))]
|
(let* ([d (mkd (build-path example-servlets "count.ss"))]
|
||||||
[ext (lambda (c)
|
[ext (lambda (c)
|
||||||
|
|
|
@ -15,15 +15,4 @@
|
||||||
(test-false "not k-url" (continuation-url? url0))
|
(test-false "not k-url" (continuation-url? url0))
|
||||||
(test-equal? "identity"
|
(test-equal? "identity"
|
||||||
(continuation-url? (string->url (embed-ids (list 1 2 3) url0)))
|
(continuation-url? (string->url (embed-ids (list 1 2 3) url0)))
|
||||||
(list 1 2 3)))
|
(list 1 2 3))))))
|
||||||
|
|
||||||
(test-suite
|
|
||||||
"xexpr/callback->xexpr"
|
|
||||||
|
|
||||||
(test-equal? "Simple"
|
|
||||||
(xexpr/callback->xexpr
|
|
||||||
(lambda _ "#")
|
|
||||||
`(html (head (title "Hello!"))
|
|
||||||
(body (a ([href ,(lambda (request) "Hey!")]) "A link"))))
|
|
||||||
`(html (head (title "Hello!"))
|
|
||||||
(body (a ([href "#"]) "A link"))))))))
|
|
Loading…
Reference in New Issue
Block a user