Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions lib/mint/http.ex
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,26 @@ defmodule Mint.HTTP do
def upgrade(old_transport, transport_state, scheme, hostname, port, opts),
do: Mint.Negotiate.upgrade(old_transport, transport_state, scheme, hostname, port, opts)

@doc """
Returns the protocol used by the current connection.

## Examples

iex> Mint.HTTP.protocol(%Mint.HTTP1{})
:http1

iex> Mint.HTTP.protocol(%Mint.HTTP2{})
:http2
"""
if Version.compare(System.version(), "1.7.0") in [:eq, :gt] do
@doc since: "1.4.0"
end

@spec protocol(t()) :: :http1 | :http2
def protocol(%Mint.HTTP1{}), do: :http1
def protocol(%Mint.HTTP2{}), do: :http2
def protocol(%Mint.UnsafeProxy{state: internal_conn}), do: protocol(internal_conn)

@doc false
@impl true
@spec initiate(
Expand Down
4 changes: 4 additions & 0 deletions test/http_test.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
defmodule Mint.HTTPTest do
use ExUnit.Case, async: true
doctest Mint.HTTP
end