adapt seval-handler to new response philosophy
FIXME: problems with input port in POST request
This commit is contained in:
parent
7fd23a0ceb
commit
a2aed3280e
|
@ -38,6 +38,15 @@
|
||||||
(syntax-rules ()
|
(syntax-rules ()
|
||||||
((do/timeout secs body ...) (do/timeout* secs (lambda () body ...)))))
|
((do/timeout secs body ...) (do/timeout* secs (lambda () body ...)))))
|
||||||
|
|
||||||
|
(define-condition-type 'seval-error '())
|
||||||
|
(define seval-error? (condition-predicate 'seval-error))
|
||||||
|
|
||||||
|
(define-condition-type 'seval-no-content-length-error '(seval-error))
|
||||||
|
(define seval-no-content-length-error?
|
||||||
|
(condition-predicate 'seval-no-content-length-error))
|
||||||
|
|
||||||
|
(define-condition-type 'seval-no-program '(seval-error))
|
||||||
|
(define seval-no-program? (condition-predicate 'seval-no-program))
|
||||||
|
|
||||||
;;; The path handler for seval ops.
|
;;; The path handler for seval ops.
|
||||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||||
|
@ -46,37 +55,65 @@
|
||||||
(let ((request-method (request:method req)))
|
(let ((request-method (request:method req)))
|
||||||
(cond
|
(cond
|
||||||
((string=? request-method "POST") ; Could do others also.
|
((string=? request-method "POST") ; Could do others also.
|
||||||
|
(call-with-current-continuation
|
||||||
|
(lambda (exit)
|
||||||
|
(begin
|
||||||
|
(with-handler
|
||||||
|
(lambda (condition more)
|
||||||
|
(exit
|
||||||
|
(cond
|
||||||
|
((seval-no-content-length-error? condition)
|
||||||
|
(make-http-error-response
|
||||||
|
http-status/bad-request req
|
||||||
|
"No `Content-length:' field in POST request."))
|
||||||
|
((seval-no-program? condition)
|
||||||
|
(make-http-error-response http-status/bad-request req
|
||||||
|
"No program in entity body."))
|
||||||
|
(else
|
||||||
|
(make-http-error-response
|
||||||
|
http-status/internal-error req
|
||||||
|
"Unknown error while evaluating seval-expression."
|
||||||
|
condition)))))
|
||||||
|
(lambda ()
|
||||||
|
(seval path req)))))))
|
||||||
|
|
||||||
(let ((modern-protocol? (not (v0.9-request? req))))
|
(else
|
||||||
(if modern-protocol?
|
(make-http-error-response http-status/method-not-allowed req)))))
|
||||||
(begin
|
|
||||||
(begin-http-header #t 200)
|
|
||||||
(write-string "Content-type: text/html\r\n\r\n")))
|
|
||||||
(with-tag #t HEAD ()
|
|
||||||
(newline)
|
|
||||||
(emit-title #t "Scheme program output"))
|
|
||||||
(newline))
|
|
||||||
|
|
||||||
(with-tag #t BODY ()
|
(define (seval path req)
|
||||||
(newline)
|
(let ((sexp (read-request-sexp req)))
|
||||||
(let ((sexp (read-request-sexp req)))
|
(http-syslog (syslog-level debug) "read sexp: ~a" sexp)
|
||||||
(do/timeout
|
(make-response
|
||||||
10
|
http-status/ok
|
||||||
(receive vals
|
(status-code->text http-status/ok)
|
||||||
;; Do the computation.
|
(time)
|
||||||
(begin (emit-header #t 2 "Output from execution")
|
"text/html"
|
||||||
(newline)
|
'()
|
||||||
(with-tag #t PRE ()
|
(make-writer-body
|
||||||
(newline)
|
(lambda (port options)
|
||||||
(force-output) ; In case we're gunned down.
|
(with-tag port HEAD ()
|
||||||
(eval-safely sexp)))
|
(newline port)
|
||||||
|
(emit-title port "Scheme program output"))
|
||||||
|
(newline port)
|
||||||
|
|
||||||
;; Pretty-print the returned value(s).
|
(with-tag port BODY ()
|
||||||
(emit-header #t 2 "Return value(s)")
|
(newline port)
|
||||||
(with-tag #t PRE ()
|
(do/timeout
|
||||||
(for-each p vals)))))))
|
10
|
||||||
|
(receive vals
|
||||||
|
;; Do the computation.
|
||||||
|
(begin (emit-header port 2 "Output from execution")
|
||||||
|
(newline port)
|
||||||
|
(with-tag port PRE ()
|
||||||
|
(newline port)
|
||||||
|
(force-output port); In case we're gunned down.
|
||||||
|
(eval-safely sexp)))
|
||||||
|
|
||||||
(else (http-error http-status/method-not-allowed #f req)))))
|
;; Pretty-print the returned value(s).
|
||||||
|
(emit-header port 2 "Return value(s)")
|
||||||
|
(with-tag port PRE ()
|
||||||
|
(for-each (lambda (val) (p val port))
|
||||||
|
vals))))))))))
|
||||||
|
|
||||||
|
|
||||||
;;; Read an HTTP request entity body from stdin. The Content-length:
|
;;; Read an HTTP request entity body from stdin. The Content-length:
|
||||||
|
@ -97,11 +134,11 @@
|
||||||
(string-length cl-str)))
|
(string-length cl-str)))
|
||||||
0)) ; All whitespace?? -- WTF.
|
0)) ; All whitespace?? -- WTF.
|
||||||
(qs (read-string cl)) ; Read in CL chars,
|
(qs (read-string cl)) ; Read in CL chars,
|
||||||
|
;; FIXME where is the input port?
|
||||||
(q (parse-html-form-query qs)) ; and parse them up.
|
(q (parse-html-form-query qs)) ; and parse them up.
|
||||||
(s (cond ((assoc "program" q) => cdr)
|
(s (cond ((assoc "program" q) => cdr)
|
||||||
(else (error "No program in entity body.")))))
|
(else (signal 'seval-no-program)))))
|
||||||
(http-syslog (syslog-level debug)
|
(http-syslog (syslog-level debug)
|
||||||
"Seval sexp:~%~s~%" s)
|
"Seval sexp: ~s" s)
|
||||||
(read (make-string-input-port s)))))
|
(read (make-string-input-port s)))))
|
||||||
(else (http-error http-status/bad-request req
|
(else (signal 'seval-no-content-length-error))))
|
||||||
"No Content-length: field in POST request."))))
|
|
||||||
|
|
|
@ -448,6 +448,7 @@
|
||||||
(open receiving ; MV return (RECEIVE and VALUES)
|
(open receiving ; MV return (RECEIVE and VALUES)
|
||||||
scsh-utilities ; index
|
scsh-utilities ; index
|
||||||
srfi-13
|
srfi-13
|
||||||
|
srfi-1 ; fold
|
||||||
let-opt ; let-optionals
|
let-opt ; let-optionals
|
||||||
crlf-io ; read-crlf-line
|
crlf-io ; read-crlf-line
|
||||||
ascii ; ascii->char
|
ascii ; ascii->char
|
||||||
|
@ -804,6 +805,7 @@
|
||||||
srfi-13 ; STRING-SKIP
|
srfi-13 ; STRING-SKIP
|
||||||
rfc822
|
rfc822
|
||||||
toothless-eval ; EVAL-SAFELY
|
toothless-eval ; EVAL-SAFELY
|
||||||
|
conditions signals
|
||||||
handle ; IGNORE-ERROR
|
handle ; IGNORE-ERROR
|
||||||
parse-html-forms ; PARSE-HTML-FORM-QUERY
|
parse-html-forms ; PARSE-HTML-FORM-QUERY
|
||||||
threads ; SLEEP
|
threads ; SLEEP
|
||||||
|
|
Loading…
Reference in New Issue