Packages

General purpose data, functions, and utilities for use by LFE/Erlang HTTP clients, servers, URL-parsers, web frameworks, etc.

Current section

Files

Jump to
lfe_http src http.response.lfe
Raw

src/http.response.lfe

(defmodule http.response
(export
(new 0) (new 1) (new 2) (new 3)
(erlang-> 1)))
(defun new ()
(new #""))
(defun new (body)
(new (http.status:ok) body))
(defun new (status body)
(new status '() body))
(defun new (status headers body)
`#m(status ,status
headers ,headers
body ,body))
(defun erlang-> (httpc-resp)
"Convert an Erlang HTTP client (httpc) response to an LFE HTTP library
response."
(let ((`#(,_ ,status-code ,_) (element 1 httpc-resp))
(headers (http.header:list->map (element 2 httpc-resp)))
(body (list_to_binary (element 3 httpc-resp))))
(new status-code headers body)))