Useful web utilities
This commit is contained in:
parent
08f1e7506b
commit
c6ca757a7e
|
@ -8,6 +8,7 @@
|
||||||
|
|
||||||
(struct-out web-request)
|
(struct-out web-request)
|
||||||
(struct-out web-request-header)
|
(struct-out web-request-header)
|
||||||
|
web-request-header-content-type
|
||||||
|
|
||||||
(rename-out [web-response-header <web-response-header>])
|
(rename-out [web-response-header <web-response-header>])
|
||||||
(struct-out/defaults [make-web-response-header web-response-header])
|
(struct-out/defaults [make-web-response-header web-response-header])
|
||||||
|
@ -26,6 +27,7 @@
|
||||||
websocket-message-recv
|
websocket-message-recv
|
||||||
websocket-message-send!
|
websocket-message-send!
|
||||||
web-respond/bytes!
|
web-respond/bytes!
|
||||||
|
web-respond/string!
|
||||||
web-respond/xexpr!
|
web-respond/xexpr!
|
||||||
|
|
||||||
spawn-web-driver)
|
spawn-web-driver)
|
||||||
|
@ -37,6 +39,7 @@
|
||||||
(require net/rfc6455/conn-api)
|
(require net/rfc6455/conn-api)
|
||||||
(require net/rfc6455/dispatcher)
|
(require net/rfc6455/dispatcher)
|
||||||
(require net/http-client)
|
(require net/http-client)
|
||||||
|
(require racket/dict)
|
||||||
(require racket/exn)
|
(require racket/exn)
|
||||||
(require racket/tcp)
|
(require racket/tcp)
|
||||||
(require racket/set)
|
(require racket/set)
|
||||||
|
@ -73,6 +76,9 @@
|
||||||
(struct web-response-chunk (id bytes) #:prefab)
|
(struct web-response-chunk (id bytes) #:prefab)
|
||||||
(struct websocket-message (id direction body) #:prefab)
|
(struct websocket-message (id direction body) #:prefab)
|
||||||
|
|
||||||
|
(define (web-request-header-content-type req)
|
||||||
|
(dict-ref (web-request-header-headers req) 'content-type #f))
|
||||||
|
|
||||||
(begin-for-declarations
|
(begin-for-declarations
|
||||||
(define-struct-defaults make-web-response-header web-response-header
|
(define-struct-defaults make-web-response-header web-response-header
|
||||||
(#:code [web-response-header-code 200]
|
(#:code [web-response-header-code 200]
|
||||||
|
@ -135,6 +141,9 @@
|
||||||
(define (web-respond/bytes! id #:header [header (make-web-response-header)] body-bytes)
|
(define (web-respond/bytes! id #:header [header (make-web-response-header)] body-bytes)
|
||||||
(send! (web-response-complete id header body-bytes)))
|
(send! (web-response-complete id header body-bytes)))
|
||||||
|
|
||||||
|
(define (web-respond/string! id #:header [header (make-web-response-header)] body-string)
|
||||||
|
(web-respond/bytes! id #:header header (string->bytes/utf-8 body-string)))
|
||||||
|
|
||||||
(define (web-respond/xexpr! id
|
(define (web-respond/xexpr! id
|
||||||
#:header [header (make-web-response-header)]
|
#:header [header (make-web-response-header)]
|
||||||
#:preamble [preamble #"<!DOCTYPE html>"]
|
#:preamble [preamble #"<!DOCTYPE html>"]
|
||||||
|
|
Loading…
Reference in New Issue