<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Thu, Feb 12, 2015 at 3:30 PM, Imants Cekusins <span dir="ltr"><<a href="mailto:imantc@gmail.com" target="_blank">imantc@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><span class="">>  I want to avoid to test at yapp level for allowable methods<br>
<br>
</span>config:<br>
arg_rewrite_mod = your_module<br>
<br>
your_module:out(Arg)-><br>
 Arg1 = test(Arg)<br>
 yapp:out(Arg1).</blockquote><div><br></div><div>Right idea, but wrong implementation. A rewriter exports arg_rewrite/1, not out/1, and it doesn't call the target resource directly but lets Yaws do that (if appropriate).</div><div><br></div><div>Here's an args rewriter that does what's required:</div><div><br></div><div><div>-module(methods_rewriter).</div><div>-export([arg_rewrite/1]).</div><div><br></div><div>-include_lib("yaws_api.hrl").</div><div><br></div><div>arg_rewrite(Arg) -></div><div>    Allowed = ['GET', 'POST'],</div><div>    Req = yaws_api:arg_req(Arg),</div><div>    Method = yaws_api:http_request_method(Req),</div><div>    case lists:member(Method, Allowed) of</div><div>        true -></div><div>            Arg;</div><div>        false -></div><div>            AllowedStrs = string:join([atom_to_list(M) || M <- Allowed], ","),</div><div>            Arg#arg{state=</div><div>                        #rewrite_response{</div><div>                           status=405,</div><div>                           headers=[{header, {"Allow", AllowedStrs}},</div><div>                                    {header, {connection, "close"}}]}}</div><div>    end.</div></div><div><br></div><div>If the incoming method is GET or POST, the dispatch continues as normal, otherwise Yaws returns a 405 Method Not Allowed and includes an Allow header indicating only GET and POST are allowed.</div><div><br></div><div>Compile this and make sure its beam is in the Yaws code load path. In the server config block for your server, set</div><div><br></div><div>arg_rewrite_mod = methods_rewriter</div><div><br></div><div>so Yaws knows to use the module for rewriting.</div><div><br></div><div>Any problems, let me know.</div><div><br></div><div>--steve</div></div></div></div>