From 164f82fff59b419588e8cf4964dea158e7f416c6 Mon Sep 17 00:00:00 2001 From: Andy LeClair Date: Wed, 21 Jul 2021 15:14:50 -0400 Subject: [PATCH 1/6] add Mint.HTTP.module/1 to describe the conn module given a conn --- lib/mint/http.ex | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/lib/mint/http.ex b/lib/mint/http.ex index c1a092fa..d597f6fd 100644 --- a/lib/mint/http.ex +++ b/lib/mint/http.ex @@ -377,6 +377,17 @@ 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 an atom describing the current connection type + + ## Examples + + Mint.HTTP1 = Mint.HTTP.module(conn) + """ + @spec module(t()) :: atom() + def module(%Mint.HTTP1{}), do: Mint.HTTP1 + def module(%Mint.HTTP2{}), do: Mint.HTTP2 + @doc false @impl true @spec initiate( From bd6dfaa3848acb24bf4968f35e8043ff19c86f9b Mon Sep 17 00:00:00 2001 From: Andy LeClair Date: Wed, 1 Sep 2021 14:15:39 -0400 Subject: [PATCH 2/6] return protocol as http1 or http2 --- lib/mint/http.ex | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/lib/mint/http.ex b/lib/mint/http.ex index d597f6fd..4a2bd990 100644 --- a/lib/mint/http.ex +++ b/lib/mint/http.ex @@ -384,9 +384,10 @@ defmodule Mint.HTTP do Mint.HTTP1 = Mint.HTTP.module(conn) """ - @spec module(t()) :: atom() - def module(%Mint.HTTP1{}), do: Mint.HTTP1 - def module(%Mint.HTTP2{}), do: Mint.HTTP2 + @spec protocol(t()) :: :http1 | :http2 + def protocol(%Mint.HTTP1{}), do: :http1 + def protocol(%Mint.UnsafeProxy{}), do: :http1 + def protocol(%Mint.HTTP2{}), do: :http2 @doc false @impl true From e295cf44b7cb11da1ec340220cb0acd30f57adee Mon Sep 17 00:00:00 2001 From: Andy LeClair Date: Wed, 1 Sep 2021 14:16:51 -0400 Subject: [PATCH 3/6] fix docstring --- lib/mint/http.ex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/mint/http.ex b/lib/mint/http.ex index 4a2bd990..e6243b30 100644 --- a/lib/mint/http.ex +++ b/lib/mint/http.ex @@ -382,7 +382,7 @@ defmodule Mint.HTTP do ## Examples - Mint.HTTP1 = Mint.HTTP.module(conn) + :http1 = Mint.HTTP.protocol(conn) """ @spec protocol(t()) :: :http1 | :http2 def protocol(%Mint.HTTP1{}), do: :http1 From 5193fe4fbe81c4cdbff11616dd7400ff5800f637 Mon Sep 17 00:00:00 2001 From: Andy LeClair Date: Wed, 1 Sep 2021 14:22:58 -0400 Subject: [PATCH 4/6] remove unsafe proxy --- lib/mint/http.ex | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/mint/http.ex b/lib/mint/http.ex index e6243b30..47310de1 100644 --- a/lib/mint/http.ex +++ b/lib/mint/http.ex @@ -386,7 +386,6 @@ defmodule Mint.HTTP do """ @spec protocol(t()) :: :http1 | :http2 def protocol(%Mint.HTTP1{}), do: :http1 - def protocol(%Mint.UnsafeProxy{}), do: :http1 def protocol(%Mint.HTTP2{}), do: :http2 @doc false From 84908f853abb5c75a85487b1bcb4941e519258a3 Mon Sep 17 00:00:00 2001 From: Andy LeClair Date: Thu, 2 Sep 2021 11:38:50 -0400 Subject: [PATCH 5/6] clean up docs, add support for unsafeproxy, doctest protocol/1 --- lib/mint/http.ex | 10 ++++++++-- test/http_test.exs | 4 ++++ 2 files changed, 12 insertions(+), 2 deletions(-) create mode 100644 test/http_test.exs diff --git a/lib/mint/http.ex b/lib/mint/http.ex index 47310de1..e152656d 100644 --- a/lib/mint/http.ex +++ b/lib/mint/http.ex @@ -378,15 +378,21 @@ defmodule Mint.HTTP do do: Mint.Negotiate.upgrade(old_transport, transport_state, scheme, hostname, port, opts) @doc """ - Returns an atom describing the current connection type + Returns the protocol used by the current connection. ## Examples - :http1 = Mint.HTTP.protocol(conn) + iex> Mint.HTTP.protocol(%Mint.HTTP1{}) + :http1 + + iex> Mint.HTTP.protocol(%Mint.HTTP2{}) + :http2 """ + @doc since: "1.4.0" @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 diff --git a/test/http_test.exs b/test/http_test.exs new file mode 100644 index 00000000..70e307c2 --- /dev/null +++ b/test/http_test.exs @@ -0,0 +1,4 @@ +defmodule Mint.HTTPTest do + use ExUnit.Case, async: true + doctest Mint.HTTP +end From 4b139ee7f34aa77538c0d4300961a7da9b92fde2 Mon Sep 17 00:00:00 2001 From: Andy LeClair Date: Fri, 10 Sep 2021 12:03:18 -0400 Subject: [PATCH 6/6] only use @doc since: in supported versions --- lib/mint/http.ex | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/mint/http.ex b/lib/mint/http.ex index e152656d..f8ca9ec2 100644 --- a/lib/mint/http.ex +++ b/lib/mint/http.ex @@ -388,7 +388,10 @@ defmodule Mint.HTTP do iex> Mint.HTTP.protocol(%Mint.HTTP2{}) :http2 """ - @doc since: "1.4.0" + 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