Packages
tz
0.20.0
0.28.2
0.28.1
0.28.0
0.27.3
0.27.2
0.27.1
0.27.0
0.26.6
0.26.5
0.26.4
0.26.3
0.26.2
0.26.1
0.26.0
0.25.1
0.25.0
0.24.0
0.23.0
0.22.0
0.21.1
0.21.0
0.20.1
0.20.0
0.19.0
0.17.0
0.16.2
0.16.1
0.16.0
0.15.0
0.14.0
0.13.0
0.12.0
0.11.0
0.10.0
0.9.0
0.8.2
0.8.1
0.8.0
0.7.3
0.7.2
0.7.1
0.7.0
0.6.0
0.5.0
0.4.0
0.3.0
0.2.0
0.1.0
Time zone support for Elixir
Current section
Files
Jump to
Current section
Files
lib/http/mint/http_client.ex
if Code.ensure_loaded?(Mint.HTTP) do
defmodule Tz.HTTP.Mint.HTTPClient do
@behaviour Tz.HTTP.HTTPClient
@moduledoc false
alias Mint.HTTP
alias Tz.HTTP.Mint.HTTPResponse, as: MintHTTPResponse
alias Tz.HTTP.HTTPResponse
@impl Tz.HTTP.HTTPClient
def request(hostname, path) do
{:ok, conn} = HTTP.connect(:https, hostname, 443)
{:ok, conn, _} = HTTP.request(conn, "GET", path, [], nil)
{:ok, response = %MintHTTPResponse{}} = recv_response(conn)
{:ok, _conn} = HTTP.close(conn)
%HTTPResponse{
status_code: response.status_code,
body: response.body
}
end
defp recv_response(conn, http_response \\ %MintHTTPResponse{}) do
receive do
message ->
{:ok, conn, mint_messages} = HTTP.stream(conn, message)
case MintHTTPResponse.parse(mint_messages, http_response) do
{:ok, http_response = %MintHTTPResponse{complete?: true}} ->
{:ok, http_response}
{:ok, http_response} ->
recv_response(conn, http_response)
error ->
error
end
end
end
end
end