Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Documentation errors #286

Closed
saleyn opened this Issue · 6 comments

2 participants

@saleyn

It seems that the documentation rules for static routes are not correct. Here the use of ' * ' is misleading:
https://github.com/extend/cowboy/blob/master/src/cowboy_static.erl#L160

The problem is that ' * ' does not have any special meaning and doesn't not really mean to match to "any" subpath (i.e. "/x/path", "/y/path"), but it means to bind a variable ' * ' with the first element in the path. It is no different than giving any other name to that variable:

3> cowboy_dispatcher:match([{'_', [{['*', <<"a">>], my, []}]}], <<"www.host.com">>, <<"/*/a">>).
{ok,my,[],[{'*',<<"*">>}],undefined,undefined}
4> cowboy_dispatcher:match([{'_', [{[x, <<"a">>], my, []}]}], <<"www.host.com">>, <<"/*/a">>).
{ok,my,[],[{x,<<"*">>}],undefined,undefined}

Finally, the documentation of ' * ' has no significance as ' * ' is not implemented in the dispatching code to serve any useful purpose:
https://github.com/extend/cowboy/blob/master/src/cowboy_dispatcher.erl#L49

The dispatch rule is only going to match if the given path is passed as ' * ' instead of a binary, which I believe never happens:

5> cowboy_dispatcher:match([{'_', [{'*', my, []}]}], <<"www.host.com">>, <<"/a/b/c/d">>).
{error,notfound,path}

6> cowboy_dispatcher:match([{'_', [{[<<"a">>,'*'], my, []}]}], <<"www.host.com">>, <<"/a/b/c/d">>).
{error,notfound,path}

7> cowboy_dispatcher:match([{'_', [{'*', my, []}]}], <<"www.host.com">>, '*').
{ok,my,[],[],undefined,undefined}
@essen
Owner

Yeah there's two issues there:

  • '*' should be '_'
  • The path '*' is now <<"*">> so the clause is wrong or not needed anymore
@essen
Owner

Thanks for spotting this!

@saleyn

Good.

@saleyn saleyn closed this
@essen
Owner

Please don't close it's not fixed yet. :)

@essen essen reopened this
@saleyn

ok

@essen
Owner

That should be fixed in 9942beb. Thanks!

@essen essen closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.