web-request-send!

This commit is contained in:
Tony Garnock-Jones 2017-10-13 13:52:45 +01:00
parent 70a56e6457
commit 0526364698
1 changed files with 21 additions and 0 deletions

View File

@ -34,6 +34,8 @@
websocket-connection-closed
websocket-message-recv
websocket-message-send!
web-request-send!
web-request-send!*
web-respond/bytes!
web-respond/string!
web-respond/xexpr!
@ -159,6 +161,25 @@
(define (websocket-message-send! id str)
(send! (websocket-message id 'outbound str)))
(define (web-request-send! id url-string
#:method [method 'GET]
#:headers [headers '()]
#:query [query #f]
#:body [body #""])
(define u (string->url url-string))
(web-request-send!* id (url->resource u)
#:method method
#:headers headers
#:query (or query (url-query u))
#:body body))
(define (web-request-send!* id resource
#:method [method 'GET]
#:headers [headers '()]
#:query [query '()]
#:body [body #f])
(send! (web-request id 'outbound (web-request-header method resource headers query) body)))
(define (web-respond/bytes! id #:header [header (make-web-response-header)] body-bytes)
(send! (web-response-complete id header body-bytes)))