[99s-extend] Rewriting URLs

Paul Dickson pdtwonotes at gmail.com
Sun Jan 25 23:30:08 CET 2015


I am trying to write a middleware step that will modify the URL in a
request before it gets to the default static request handler.  I can not
find an example of how to do this.  What I have so far:

execute( Req, Env ) ->
    HostUrl = cowboy_req:host_url(Req),
    NewUrl = rewrite( HostUrl ),
    NewReq = ???
    {ok, NewReq, Env}.

How do I modify a Request object so that it contains my modified URL,
which cowboy_static will then process normally?  My 'rewrite' function
converts logical directory names into real file-system paths, using a
dynamic algorithm that can not be simply written into cowboy's dispatch
rules.

The dispatch rules I am using is as follows, where 'bz_libmap' is my
module containing the code above:
	    {"/music/[...]", cowboy_static, {dir, bz_libmap, ""}},

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.ninenines.eu/archives/extend/attachments/20150125/370811e4/attachment.html>


More information about the Extend mailing list