[erlang-questions] configure http methods in yaws
Steve Vinoski
vinoski@REDACTED
Thu Feb 12 23:51:49 CET 2015
On Thu, Feb 12, 2015 at 5:38 PM, Imants Cekusins <imantc@REDACTED> wrote:
> > A rewriter exports arg_rewrite/1, not out/1,
>
> ta, Steve.
>
> btw arg_rewrite output spec format:
>
> Arg#arg{
> state = #rewrite_response{ }
> }
>
> is documented @
>
> https://github.com/klacke/yaws/blob/master/test/t2/rewritetest.erl
>
> I should have checked.
>
That's a test for the feature, but you can find documentation here:
http://yaws.hyber.org/yaws.pdf
BTW I now realize why your example called yapp:out(Arg1): the OP uses
yapps, so his arg_rewrite_mod setting will already be set to yapp, so my
example needs to take that into account too. It should be the following
instead:
-module(methods_rewriter).
-export([arg_rewrite/1]).
-include_lib("yaws_api.hrl").
arg_rewrite(Arg) ->
Allowed = ['GET', 'POST'],
Req = yaws_api:arg_req(Arg),
Method = yaws_api:http_request_method(Req),
case lists:member(Method, Allowed) of
true ->
yapp:arg_rewrite(Arg);
false ->
AllowedStrs = string:join([atom_to_list(M) || M <- Allowed],
","),
Arg#arg{state=
#rewrite_response{
status=405,
headers=[{header, {"Allow", AllowedStrs}},
{header, {connection, "close"}}]}}
end.
The difference is that when the method is allowed, we call
yapp:arg_rewrite/1 instead of just returning Arg.
--steve
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20150212/8752e781/attachment.htm>
More information about the erlang-questions
mailing list