diff --git a/src/gleam/hackney.gleam b/src/gleam/hackney.gleam index 3cdd77d..37f207e 100644 --- a/src/gleam/hackney.gleam +++ b/src/gleam/hackney.gleam @@ -15,28 +15,41 @@ pub type Error { Other(Dynamic) } +pub type Option { + WithBody(Bool) + ConnectTimeout(Int) + RecvTimeout(Int) +} + @external(erlang, "gleam_hackney_ffi", "send") fn ffi_send( a: Method, b: String, c: List(http.Header), d: BytesTree, + e: List(Option), ) -> Result(Response(BitArray), Error) -// TODO: test -pub fn send_bits( - request: Request(BytesTree), -) -> Result(Response(BitArray), Error) { +pub fn dispatch_bits(request, options) { use response <- result.try( request |> request.to_uri |> uri.to_string - |> ffi_send(request.method, _, request.headers, request.body), + |> ffi_send(request.method, _, request.headers, request.body, options), ) let headers = list.map(response.headers, normalise_header) Ok(Response(..response, headers: headers)) } +// TODO: test +pub fn send_bits( + request: Request(BytesTree), +) -> Result(Response(BitArray), Error) { + dispatch_bits(request, [ + WithBody(True), + ]) +} + pub fn send(req: Request(String)) -> Result(Response(String), Error) { use resp <- result.try( req diff --git a/src/gleam_hackney_ffi.erl b/src/gleam_hackney_ffi.erl index ca01f15..91736ce 100644 --- a/src/gleam_hackney_ffi.erl +++ b/src/gleam_hackney_ffi.erl @@ -1,9 +1,8 @@ -module(gleam_hackney_ffi). --export([send/4]). +-export([send/5]). -send(Method, Url, Headers, Body) -> - Options = [{with_body, true}], +send(Method, Url, Headers, Body, Options) -> case hackney:request(Method, Url, Headers, Body, Options) of {ok, Status, ResponseHeaders, ResponseBody} -> {ok, {response, Status, ResponseHeaders, ResponseBody}};