mirror of
https://github.com/teo3300/rust-mal.git
synced 2026-01-12 09:15:32 +01:00
Adding requests
Should be a small library to write http1 requests
This commit is contained in:
28
libs/requests.mal
Normal file
28
libs/requests.mal
Normal file
@ -0,0 +1,28 @@
|
||||
(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 ""))))
|
||||
|
||||
Reference in New Issue
Block a user