Last active
November 19, 2024 21:31
-
-
Save eproxus/bd40f3a06e2c78dea539d2ba0471e36f to your computer and use it in GitHub Desktop.
Revisions
-
eproxus revised this gist
Nov 4, 2023 . 1 changed file with 0 additions and 4 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,9 +1,5 @@ # How to Create a Cowboy Middleware Add an entry to the `middlewares`. Usually you want to keep the standard Cowboy handlers afterwards, but you can replace them if you want. -
eproxus renamed this gist
Jun 6, 2021 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes. -
eproxus revised this gist
Jun 2, 2021 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,4 +1,4 @@ # How to Create a Cowboy Middleware | :warning: | |:-----------| -
eproxus revised this gist
Jun 2, 2021 . 1 changed file with 3 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,3 +1,5 @@ # How To Create a Cowboy Middleware | :warning: | |:-----------| |Middlewares are "deprecated" because stream handlers can do everything middlewares can do and more. Consider using a stream handler instead. | @@ -17,7 +19,7 @@ handlers afterwards, but you can replace them if you want. A middleware implements the behavior `cowboy_middleware`. ## Caveats * You cannot change a response after it has been sent. For example, if you add a middleware after the generic `cowboy_handler` middleware. If a previous -
eproxus revised this gist
Jun 2, 2021 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,5 +1,5 @@ | :warning: | |:-----------| |Middlewares are "deprecated" because stream handlers can do everything middlewares can do and more. Consider using a stream handler instead. | Add an entry to the `middlewares`. Usually you want to keep the standard Cowboy -
eproxus revised this gist
Jun 2, 2021 . 1 changed file with 2 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,6 +1,6 @@ | :warning: | |:---------:| |Middlewares are "deprecated" because stream handlers can do everything middlewares can do and more. Consider using a stream handler instead. | Add an entry to the `middlewares`. Usually you want to keep the standard Cowboy handlers afterwards, but you can replace them if you want. -
eproxus revised this gist
Jun 2, 2021 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,6 +1,6 @@ | :warning: | |:---------:| | Middlewares are "deprecated" because stream handlers can do everything middlewares can do and more. Consider using a stream handler instead. | Add an entry to the `middlewares`. Usually you want to keep the standard Cowboy handlers afterwards, but you can replace them if you want. -
eproxus created this gist
Jun 2, 2021 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,26 @@ | :warning: | |:---------:| |foo | Add an entry to the `middlewares`. Usually you want to keep the standard Cowboy handlers afterwards, but you can replace them if you want. ```erlang {ok, Pid} = cowboy:start_clear(ListenerName, [{port, Port}], #{ env => #{dispatch => Dispatch}, middlewares => [my_middleware, cowboy_router, cowboy_handler] } ), ``` A middleware implements the behavior `cowboy_middleware`. # Caveats * You cannot change a response after it has been sent. For example, if you add a middleware after the generic `cowboy_handler` middleware. If a previous middleware has called the `cowboy_req:reply/4` function the response has already been sent on the wire. For that purpose you need to use a stream handler instead. This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,9 @@ -module(my_middleware). -behaviour(cowboy_middleware). -export([execute/2]). execute(Req, Env) -> io:format("~p request~n", [cowboy_req:method(Req)]), {ok, Req2, Env}.