From 67184faf777eb90caee6f320da871f8a3d773cd9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lennart=20Fride=CC=81n?= Date: Sun, 5 Apr 2015 12:06:41 +0200 Subject: [PATCH] No need to handle nil header values. --- README.md | 19 +++++++++++++++---- lib/plug_require_header.ex | 2 +- mix.exs | 2 +- 3 files changed, 17 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index c03b1ba..f7bc847 100644 --- a/README.md +++ b/README.md @@ -15,7 +15,10 @@ defp deps do end ``` -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. +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. ```elixir defmodule MyPhoenixApp.MyController do use MyPhoenixApp.Web, :controller @@ -31,9 +34,14 @@ defmodule MyPhoenixApp.MyController do end end ``` -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. +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. -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. +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` as the underlying HTTP server will +not include the header. This behaviour however is configurable. ```elixir defmodule MyPhoenixApp.MyOtherController do use MyPhoenixApp.Web, :controller @@ -55,7 +63,10 @@ defmodule MyPhoenixApp.MyOtherController do end end ``` -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. +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. Lastly, it's possible to extract multiple headers at the same time. diff --git a/lib/plug_require_header.ex b/lib/plug_require_header.ex index 5489264..a6737c0 100644 --- a/lib/plug_require_header.ex +++ b/lib/plug_require_header.ex @@ -2,7 +2,7 @@ defmodule PlugRequireHeader do import Plug.Conn alias Plug.Conn.Status - @vsn "0.3.0" + @vsn "0.3.1" @doc false def version, do: @vsn diff --git a/mix.exs b/mix.exs index af6af9f..6e55f34 100644 --- a/mix.exs +++ b/mix.exs @@ -4,7 +4,7 @@ defmodule PlugRequireHeader.Mixfile do def project do [ app: :plug_require_header, - version: "0.3.0", + version: "0.3.1", name: "PlugRequireHeader", source_url: "https://github.com/DevL/plug_require_header", elixir: "~> 1.0",