mirror of
https://github.com/teo3300/rust-mal.git
synced 2026-01-12 01:05:32 +01:00
29 lines
741 B
Plaintext
29 lines
741 B
Plaintext
(module "string")
|
|
|
|
(def! +http-version+ "HTTP/1.1")
|
|
|
|
(def! #r (char "\r"))
|
|
|
|
(def! headers->string (fn* [headers]
|
|
(if (list? headers)
|
|
(join (map header->string headers) "")
|
|
(if (string? headers) headers))))
|
|
|
|
(def! header->string (fn* [header]
|
|
(str (car header) ":" (car (cdr header)) #r #n)))
|
|
|
|
(def! make-http-req (fn* [method target headers content]
|
|
(str method #s target #s +http-version+
|
|
#r #n
|
|
(or (headers->string headers) "")
|
|
#r #n
|
|
(or content ""))))
|
|
|
|
(def! make-http-res (fn* [status-code reason-phrase headers data]
|
|
(str +http-version+ #s status-code #s reason-phrase
|
|
#r #n
|
|
(or (headers->string headers) "")
|
|
#r #n
|
|
(or data ""))))
|
|
|