diff --git a/README.md b/README.md index 7f5d8d86..81ebdc41 100644 --- a/README.md +++ b/README.md @@ -51,7 +51,6 @@ iex> flush() Users are not supposed to examine these messages. Instead, Mint provides a `stream/2` function that turns messages into HTTP responses. Mint streams responses back to the user in parts through response parts such as `:status`, `:headers`, `:data`, and `:done`. - ```elixir iex> {:ok, conn} = Mint.HTTP.connect(:https, "httpbin.org", 443) iex> {:ok, conn, request_ref} = Mint.HTTP.request(conn, "GET", "/", [], "") @@ -151,7 +150,6 @@ Copyright 2018 Eric Meadows-Jönsson and Andrea Leopardi See the License for the specific language governing permissions and limitations under the License. -[castore]: https://github.com/elixir-mint/castore [documentation]: https://hexdocs.pm/mint [issues]: https://github.com/elixir-mint/mint/issues [mint_web_socket]: https://github.com/elixir-mint/mint_web_socket diff --git a/test/mint/http1/integration_test.exs b/test/mint/http1/integration_test.exs index 0135aafe..17f6dfa7 100644 --- a/test/mint/http1/integration_test.exs +++ b/test/mint/http1/integration_test.exs @@ -185,7 +185,7 @@ defmodule Mint.HTTP1.IntegrationTest do HTTP1.connect( :https, "localhost", - 8443, + Mint.HttpBin.https_port(), transport_opts: [cacerts: [], log_alert: false, reuse_sessions: false] ) diff --git a/test/mint/http2/integration_test.exs b/test/mint/http2/integration_test.exs index d7790346..3a901c63 100644 --- a/test/mint/http2/integration_test.exs +++ b/test/mint/http2/integration_test.exs @@ -77,65 +77,9 @@ defmodule HTTP2.IntegrationTest do assert conn.buffer == "" assert HTTP2.open?(conn) end - end - - describe "http2.golang.org" do - @describetag skip: """ - http2.golang.org has been decommisioned. - Re-enable these tests in the future if we figure out a test server that supports - a similar set of features. - """ - - test "GET /clockstream", %{conn: conn} do - assert {:ok, %HTTP2{} = conn, req_id} = HTTP2.request(conn, "GET", "/clockstream", [], nil) - - assert {:ok, %HTTP2{} = conn, responses} = stream_messages_until_response(conn) - assert [{:status, ^req_id, 200}, {:headers, ^req_id, _headers} | rest] = responses - - conn = - if rest != [] do - assert [{:data, ^req_id, data}] = rest - assert data =~ "# ~1KB of junk to force browsers to start rendering immediately" - conn - else - assert_receive message, 5000 - assert {:ok, %HTTP2{} = conn, responses} = HTTP2.stream(conn, message) - assert [{:data, ^req_id, data}] = responses - assert data =~ "# ~1KB of junk to force browsers to start rendering immediately" - conn - end - - assert_receive message, 5000 - assert {:ok, %HTTP2{} = conn, responses} = HTTP2.stream(conn, message) - assert [{:data, ^req_id, data}] = responses - assert data =~ ~r/\A\d{4}-\d{2}-\d{2}/ - - assert HTTP2.open?(conn) - end - - test "PUT /ECHO", %{conn: conn} do - assert {:ok, %HTTP2{} = conn, req_id} = - HTTP2.request(conn, "PUT", "/ECHO", [], "hello world") - - assert {:ok, %HTTP2{} = conn, responses} = receive_stream(conn) - - assert [ - {:status, ^req_id, 200}, - {:headers, ^req_id, headers}, - {:data, ^req_id, data}, - {:data, ^req_id, ""}, - {:done, ^req_id} - ] = responses - assert is_list(headers) - assert data == "HELLO WORLD" - - assert conn.buffer == "" - assert HTTP2.open?(conn) - end - - test "GET /file/gopher.png", %{conn: conn} do - assert {:ok, %HTTP2{} = conn, ref} = HTTP2.request(conn, "GET", "/file/gopher.png", [], nil) + test "GET /image/png", %{conn: conn} do + assert {:ok, %HTTP2{} = conn, ref} = HTTP2.request(conn, "GET", "/image/png", [], nil) assert {:ok, %HTTP2{} = conn, responses} = receive_stream(conn) assert [ @@ -143,14 +87,12 @@ defmodule HTTP2.IntegrationTest do {:headers, ^ref, headers}, {:data, ^ref, data1}, {:data, ^ref, data2}, - {:data, ^ref, data3}, {:done, ^ref} ] = responses assert is_list(headers) assert is_binary(data1) assert is_binary(data2) - assert is_binary(data3) assert conn.buffer == "" assert HTTP2.open?(conn) @@ -162,19 +104,6 @@ defmodule HTTP2.IntegrationTest do assert conn.buffer == "" assert HTTP2.open?(conn) end - - test "GET /serverpush", %{conn: conn} do - assert {:ok, %HTTP2{} = conn, req_id} = HTTP2.request(conn, "GET", "/serverpush", [], nil) - assert {:ok, %HTTP2{} = _conn, responses} = receive_stream(conn) - - # TODO: improve this test by improving receive_stream/1. - assert [ - {:push_promise, ^req_id, _promised_req_id1, _headers1}, - {:push_promise, ^req_id, _promised_req_id2, _headers2}, - {:push_promise, ^req_id, _promised_req_id3, _headers3}, - {:push_promise, ^req_id, _promised_req_id4, _headers4} | _ - ] = responses - end end describe "twitter.com" do @@ -329,14 +258,5 @@ defmodule HTTP2.IntegrationTest do end end - defp stream_messages_until_response(conn) do - assert_receive message, 1000 - - case HTTP2.stream(conn, message) do - {:ok, %HTTP2{} = conn, []} -> stream_messages_until_response(conn) - other -> other - end - end - # TODO: certificate verification; badssl.com does not seem to support HTTP2 end diff --git a/test/mint/integration_test.exs b/test/mint/integration_test.exs index 5e1fdf98..dc2ef74f 100644 --- a/test/mint/integration_test.exs +++ b/test/mint/integration_test.exs @@ -9,10 +9,14 @@ defmodule Mint.IntegrationTest do describe "nghttp2.org" do test "SSL - select HTTP1" do - assert {:ok, conn} = HTTP.connect(:https, "nghttp2.org", 443, protocols: [:http1]) + assert {:ok, conn} = + HTTP.connect(:https, HttpBin.host(), HttpBin.https_port(), + transport_opts: HttpBin.https_transport_opts(), + protocols: [:http1] + ) assert conn.__struct__ == Mint.HTTP1 - assert {:ok, conn, request} = HTTP.request(conn, "GET", "/httpbin/bytes/1", [], nil) + assert {:ok, conn, request} = HTTP.request(conn, "GET", "/bytes/1", [], nil) assert {:ok, _conn, responses} = receive_stream(conn) assert [ @@ -24,10 +28,13 @@ defmodule Mint.IntegrationTest do end test "SSL - select HTTP2" do - assert {:ok, conn} = HTTP.connect(:https, "nghttp2.org", 443) + assert {:ok, conn} = + HTTP.connect(:https, HttpBin.host(), HttpBin.https_port(), + transport_opts: HttpBin.https_transport_opts() + ) assert conn.__struct__ == Mint.HTTP2 - assert {:ok, conn, request} = HTTP.request(conn, "GET", "/httpbin/bytes/1", [], nil) + assert {:ok, conn, request} = HTTP.request(conn, "GET", "/bytes/1", [], nil) assert {:ok, _conn, responses} = receive_stream(conn) assert [ diff --git a/test/mint/unix_socket_test.exs b/test/mint/unix_socket_test.exs index f1605432..5d767a80 100644 --- a/test/mint/unix_socket_test.exs +++ b/test/mint/unix_socket_test.exs @@ -1,4 +1,4 @@ -defmodule Mint.UnitSocketTest do +defmodule Mint.UnixSocketTest do use ExUnit.Case, async: true alias Mint.{HTTP, TestSocketServer}