Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Mint - Disrupting HTTP clients

Mint - Disrupting HTTP clients

Andrea Leopardi

August 29, 2019
Tweet

More Decks by Andrea Leopardi

Other Decks in Programming

Transcript

  1. {:ok, conn} =
    Mint.HTTP.connect(
    :https,
    "example.com",
    80
    )
    conn
    #=> %Mint.HTTP1{...}

    View full-size slide

  2. {:ok, conn, request_ref} =
    Mint.HTTP.request(
    conn,
    "GET",
    "/",
    [{"content-type", "text/html"}]
    )

    View full-size slide

  3. {:ok, conn, request_ref} =
    Mint.HTTP.request(...)

    View full-size slide

  4. receive do
    message ->
    Mint.HTTP.stream(conn, message)
    end

    View full-size slide

  5. case Mint.HTTP.stream(conn, message) do
    :unknown ->
    # ...
    {:ok, conn, responses} ->
    # ...
    {:error, conn, reason, responses} ->
    # ...
    end

    View full-size slide

  6. {:status, ref, 200}
    {:headers, ref, [...]}
    {:data, ref, "...chunk..."}
    {:done, ref}
    {:error, ref, reason}

    View full-size slide

  7. :inets.start()
    :ssl.start()
    :httpc.request(
    'https://self-signed.badssl.com'
    )
    #=> {:ok, {{'HTTP/1.1', 200, 'OK'}...}

    View full-size slide

  8. :hackney.request(
    :get,
    "https://self-signed.badssl.com",
    _headers = [],
    _body = "",
    _opts = []
    )
    #=> {:error, {:tls_alert, ...}}

    View full-size slide

  9. :hackney.request(
    :get,
    "https://self-signed.badssl.com",
    _headers = [],
    _body = "",
    ssl_options: [versions: [:"tlsv1.2"]]
    )
    #=> {:ok, 200, ...}

    View full-size slide

  10. Mint.HTTP.connect(
    :https,
    "https://self-signed.badssl.com",
    443
    )
    #=> {:error, %Mint.TransportError{...}}

    View full-size slide

  11. defp deps do
    [
    # ...,
    {:mint, "~> 0.4"},
    {:castore, "~> 0.1"}
    ]
    end

    View full-size slide

  12. proxy = {
    :http,
    "proxy.example.com",
    80,
    _opts = []
    }
    Mint.HTTP.connect(
    :https,
    "httpbin.org",
    443,
    proxy: proxy
    )

    View full-size slide

  13. {
    :push_promise,
    ref,
    promised_ref,
    promised_headers
    }

    View full-size slide

  14. {:ok, conn, ref} =
    Mint.HTTP2.ping(conn)
    # ...
    response
    #=> {:pong, ^ref}

    View full-size slide

  15. Mint.HTTP.connect(...)
    Mint.HTTP1.connect(...)
    Mint.HTTP2.connect(...)

    View full-size slide