7 Utilities
7.1 URL Utilities
(require http123/util/url) | package: http123-lib |
procedure
(build-url base-url path-part ... [ #:query query]) → url? base-url : (or/c url? string?) path-part : (or/c string? path/param?) query : (listof (cons/c symbol? (or/c #f string?))) = null
Each path-part is added to the end of base’s existing path. If
path-part is a string, it is first split on / characters,
"." and ".." segments are converted to 'same and
'up, respectively, and then each segment is wrapped in a
path/param with no parameters. Note that the path-part strings
are not decoded—
The path is then simplified as follows: 'up and 'same segments are collapsed unless doing so would delete parameters, and empty path segments are removed except that an empty segment is allowed at the end of the path. (An empty segment at the end corresponds to a URL written with a final /.)
The query is appended to the end of base-url’s existing query arguments.
procedure
(ok-http-url? v) → boolean?
v : any/c
the scheme is "http" or "https" (compared case-insensitively)
the user field is absent (#f)
the host field is present
the path is marked as absolute
> (ok-http-url? (string->url "http://racket-lang.org/")) #t
> (ok-http-url? (string->url "http://ryanc@racket-lang.org/")) #f
> (ok-http-url? (string->url "ftp://mirror.racket-lang.org/")) #f
> (ok-http-url? (string->url "somewhere/out-there.html")) #f
7.2 Header Utilities
(require http123/util/header) | package: http123-lib |
"Accept-Encoding: gzip, deflate " '(accept-language #"en") '(#"User-Agent" #"racket-http123/0.1")
value
=
(list/c (and/c bytes? immutable? ...lowercase-token-rx...) (and/c bytes? immutable? ...field-value-rx...))
'(#"accept-encoding" #"gzip, deflate") '(#"accept-language" #"en") '(#"user-agent" #"racket-http123/0.1")
procedure
(check-header-field in) → header-field/c
in : in-header-field/c
procedure
(header-field-list-update base-header ext-header) → (listof header-field/c) base-header : (listof header-field/c) ext-header : (listof header-field/c)
7.3 Request Utilities
(require http123/util/request) | package: http123-lib |
procedure
(request/json method url header json-data [ #:write? write?]) → request? method : method/c url : (or/c string? url?) header : (listof in-header-field/c) json-data : jsexpr? write? : boolean? = #f
If write? is false, then json-data is immediately converted to a byte string. Otherwise, the request contains a procedure that writes json-data on demand.
procedure
(request/form-urlencoded method url header form-data) → request? method : method/c url : (or/c string? url?) header : (listof in-header-field/c) form-data : (listof (cons/c symbol? (or/c #f string?)))
procedure
(request/multipart method url header data) → request?
method : method/c url : (or/c string? url?) header : (listof in-header-field/c)
data :
(listof (let* ([name/c (or/c string? symbol? bytes?)] [value/c (or/c string? bytes? procedure?)] [in-header/c (listof in-header-field/c)]) (or/c (list/c name/c value/c) (list/c name/c value/c in-header/c) (list/c name/c value/c in-header/c '#:filename name/c))))
(list name value) —
Consists of a form field name and its corresponding value. Example: (list "language" "en"). (list name value header) —
Like the previous form, but also includes a header that describes this field. Example: (list "subtotal" "€20" '("content-type: text/plain;charset=utf-8")) (list name value header '#:filename filename) —
Like the previous form, but indicates that the part corresponds to a file with the given filename.