Skip to content
This repository was archived by the owner on Mar 10, 2025. It is now read-only.

Commit 67184fa

Browse files
committed
No need to handle nil header values.
1 parent 04e7cb1 commit 67184fa

File tree

3 files changed

+17
-6
lines changed

3 files changed

+17
-6
lines changed

README.md

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,10 @@ defp deps do
1515
end
1616
```
1717

18-
Add the plug to e.g. a pipeline in a [Phoenix](http://www.phoenixframework.org/) controller. In this case we will require the request header `x-api-key` to be set, extract its first value and assign it the connection (a `Plug.Conn`) for later use in another plug or action.
18+
Add the plug to e.g. a pipeline in a [Phoenix](http://www.phoenixframework.org/)
19+
controller. In this case we will require the request header `x-api-key` to be set,
20+
extract its first value and assign it the connection (a `Plug.Conn`) for later use
21+
in another plug or action.
1922
```elixir
2023
defmodule MyPhoenixApp.MyController do
2124
use MyPhoenixApp.Web, :controller
@@ -31,9 +34,14 @@ defmodule MyPhoenixApp.MyController do
3134
end
3235
end
3336
```
34-
Notice how the first value required header `"x-api-key"` has been extracted and can be retrieved using `conn.assigns[:api_key]`. An alternative is to use `Plug.Conn.get_req_header/2` to get all the values associated with a given header.
37+
Notice how the first value required header `"x-api-key"` has been extracted
38+
and can be retrieved using `conn.assigns[:api_key]`. An alternative is to use
39+
`Plug.Conn.get_req_header/2` to get all the values associated with a given header.
3540

36-
By default, a missing header will return a status code of 403 (forbidden) and halt the plug pipeline, i.e. no subsequent plugs will be executed. The same is true if the required header is explicitly set to `nil`. This behaviour however is configurable.
41+
By default, a missing header will return a status code of 403 (forbidden) and halt
42+
the plug pipeline, i.e. no subsequent plugs will be executed. The same is true if
43+
the required header is explicitly set to `nil` as the underlying HTTP server will
44+
not include the header. This behaviour however is configurable.
3745
```elixir
3846
defmodule MyPhoenixApp.MyOtherController do
3947
use MyPhoenixApp.Web, :controller
@@ -55,7 +63,10 @@ defmodule MyPhoenixApp.MyOtherController do
5563
end
5664
end
5765
```
58-
If the header is missing or set to `nil` the status code, a status code of 400 (bad request) will be returned before the plug pipeline is halted. Notice that the function specified as a callback needs to be a public function as it'll be invoked from another module.
66+
If the header is missing or set to `nil` the status code, a status code of 400
67+
(bad request) will be returned before the plug pipeline is halted. Notice that
68+
the function specified as a callback needs to be a public function as it'll be
69+
invoked from another module.
5970

6071
Lastly, it's possible to extract multiple headers at the same time.
6172

lib/plug_require_header.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ defmodule PlugRequireHeader do
22
import Plug.Conn
33
alias Plug.Conn.Status
44

5-
@vsn "0.3.0"
5+
@vsn "0.3.1"
66
@doc false
77
def version, do: @vsn
88

mix.exs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ defmodule PlugRequireHeader.Mixfile do
44
def project do
55
[
66
app: :plug_require_header,
7-
version: "0.3.0",
7+
version: "0.3.1",
88
name: "PlugRequireHeader",
99
source_url: "https://github.com/DevL/plug_require_header",
1010
elixir: "~> 1.0",

0 commit comments

Comments
 (0)