Skip to content

Commit

Permalink
Remove redundant code path and test.
Browse files Browse the repository at this point in the history
The HTTP server will not include headers with nil values even if they
are set as part of the request.

For more info, see elixir-plug/plug#220
  • Loading branch information
DevL committed Apr 5, 2015
1 parent 75b822d commit 04e7cb1
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 13 deletions.
1 change: 0 additions & 1 deletion lib/plug_require_header.ex
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ defmodule PlugRequireHeader do

defp extract_header_key(conn, {connection_key, header_key}, callback) do
case List.keyfind(conn.req_headers, header_key, 0) do
{^header_key, nil} -> callback.(conn, header_key)
{^header_key, value} -> assign_connection_key(conn, connection_key, value)
_ -> callback.(conn, header_key)
end
Expand Down
12 changes: 0 additions & 12 deletions test/plug_require_header_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,6 @@ defmodule PlugRequireHeaderTest do
assert response.resp_body == ""
end

test "block request with the required header set to nil" do
connection = conn(:get, "/") |> put_nil_header("x-api-key")
response = TestApp.call(connection, [])

assert response.status == Status.code(:forbidden)
assert response.resp_body == ""
end

test "extract the required header and assign it to the connection" do
connection = conn(:get, "/") |> put_req_header("x-api-key", "12345")
response = TestApp.call(connection, [])
Expand Down Expand Up @@ -71,8 +63,4 @@ defmodule PlugRequireHeaderTest do
assert response.status == Status.code(:bad_request)
assert response.resp_body == "Missing header: x-secret"
end

defp put_nil_header(%Plug.Conn{req_headers: headers} = conn, key) when is_binary(key) do
%{conn | req_headers: :lists.keystore(key, 1, headers, {key, nil})}
end
end

0 comments on commit 04e7cb1

Please sign in to comment.