Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement no-op support for Plug.Conn.Adapter.upgrade/3 #34

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions lib/bandit/http1/adapter.ex
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,9 @@ defmodule Bandit.HTTP1.Adapter do
@impl Plug.Conn.Adapter
def inform(_req, _status, _headers), do: {:error, :not_supported}

@impl Plug.Conn.Adapter
def upgrade(_req, _upgrade, _opts), do: {:error, :not_supported}

@impl Plug.Conn.Adapter
def push(_req, _path, _headers), do: {:error, :not_supported}

Expand Down
3 changes: 3 additions & 0 deletions lib/bandit/http2/adapter.ex
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,9 @@ defmodule Bandit.HTTP2.Adapter do
GenServer.call(adapter.connection, {:send_headers, adapter.stream_id, headers, false})
end

@impl Plug.Conn.Adapter
def upgrade(_req, _upgrade, _opts), do: {:error, :not_supported}

@impl Plug.Conn.Adapter
def push(_adapter, _path, _headers), do: {:error, :not_supported}

Expand Down
17 changes: 17 additions & 0 deletions test/bandit/http1/request_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,23 @@ defmodule HTTP1RequestTest do
end
end

describe "upgrade handling" do
test "does not update the conn or send any data on unsupported upgrades", context do
{:ok, response} =
Finch.build(:get, context[:base] <> "/upgrade_unsupported", [{"connection", "close"}])
|> Finch.request(context[:finch_name])

assert response.status == 200
assert response.body == "Not supported"
end

def upgrade_unsupported(conn) do
conn
|> upgrade_adapter(:unsupported, [])
|> send_resp(200, "Not supported")
end
end

test "does not do anything special with EXIT messages from abnormally terminating spwaned processes",
context do
errors =
Expand Down
17 changes: 17 additions & 0 deletions test/bandit/http2/plug_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,23 @@ defmodule HTTP2PlugTest do
|> elem(1)
end

describe "upgrade handling" do
test "does not update the conn or send any data on unsupported upgrades", context do
{:ok, response} =
Finch.build(:get, context[:base] <> "/upgrade_unsupported")
|> Finch.request(context[:finch_name])

assert response.status == 200
assert response.body == "Not supported"
end

def upgrade_unsupported(conn) do
conn
|> upgrade_adapter(:unsupported, [])
|> send_resp(200, "Not supported")
end
end

test "raises a Plug.Conn.NotSentError if nothing was set in the conn", context do
errors =
capture_log(fn ->
Expand Down