cowboy_static chokes #308

Closed
dvv opened this Issue Nov 2, 2012 · 8 comments

Comments

Projects
None yet
2 participants
@dvv
Contributor

dvv commented Nov 2, 2012

if request uri matches uri in dispatch rule and file key is not specified in static handler options, check_path/1 takes undefined which doesn't match any pattern.

    {[<<"public">>], cowboy_static, [
      {directory, {priv_dir, example, [<<"www">>]}},
      %{file, <<"index.html">>},
      {mimetypes, {fun mimetypes:path_to_mimes/2, default}}
    ]}
> GET /public HTTP/1.1
> User-Agent: curl/7.28.0
> Host: localhost:8080
> Accept: */*
>
< HTTP/1.1 500 Internal Server Error
...
> GET /public/ HTTP/1.1
> User-Agent: curl/7.28.0
> Host: localhost:8080
> Accept: */*
>
< HTTP/1.1 500 Internal Server Error
...
> GET /public// HTTP/1.1
> User-Agent: curl/7.28.0
> Host: localhost:8080
> Accept: */*
>
< HTTP/1.1 404 Not Found
<
@dvv

This comment has been minimized.

Show comment Hide comment
@dvv

dvv Nov 2, 2012

Contributor

turns out path_info/1 is unsafe to use -- it may report undefined both on exact uri match and after calling compact on request.
please consider fixing

Contributor

dvv commented Nov 2, 2012

turns out path_info/1 is unsafe to use -- it may report undefined both on exact uri match and after calling compact on request.
please consider fixing

@essen

This comment has been minimized.

Show comment Hide comment
@essen

essen Nov 2, 2012

Member

Probably a recent change broke it!

Member

essen commented Nov 2, 2012

Probably a recent change broke it!

@dvv

This comment has been minimized.

Show comment Hide comment
@dvv

dvv Nov 2, 2012

Contributor

one must specify '...' after the uri if he doesn't provide file key.

    {[<<"public">>, '...'], cowboy_static, [
      {directory, {priv_dir, example, [<<"www">>]}},
      %{file, <<"index.html">>},
      {mimetypes, {fun mimetypes:path_to_mimes/2, default}}
    ]}

this done, things go well.
i do treat this a quirk as error bubbles at not evident place.
may be we should imply '...' unless file is given, or error on missing file unless '...' is given? or fix dispatch matcher.

Contributor

dvv commented Nov 2, 2012

one must specify '...' after the uri if he doesn't provide file key.

    {[<<"public">>, '...'], cowboy_static, [
      {directory, {priv_dir, example, [<<"www">>]}},
      %{file, <<"index.html">>},
      {mimetypes, {fun mimetypes:path_to_mimes/2, default}}
    ]}

this done, things go well.
i do treat this a quirk as error bubbles at not evident place.
may be we should imply '...' unless file is given, or error on missing file unless '...' is given? or fix dispatch matcher.

@essen

This comment has been minimized.

Show comment Hide comment
@essen

essen Nov 2, 2012

Member

OK then I probably misunderstood. If you are trying to serve files inside a directory then yes you need the '...'. If you need to serve a specific file under a specific path then you need the file option.

Member

essen commented Nov 2, 2012

OK then I probably misunderstood. If you are trying to serve files inside a directory then yes you need the '...'. If you need to serve a specific file under a specific path then you need the file option.

@dvv

This comment has been minimized.

Show comment Hide comment
@dvv

dvv Nov 2, 2012

Contributor

this is right.
wrong imho is that path_info/1 returns undefined instead of [] for [<<"public">>] rule when one does GET /public.
feel free to close the issue, as i seem to have coped with it.

Contributor

dvv commented Nov 2, 2012

this is right.
wrong imho is that path_info/1 returns undefined instead of [] for [<<"public">>] rule when one does GET /public.
feel free to close the issue, as i seem to have coped with it.

@dvv

This comment has been minimized.

Show comment Hide comment
@dvv

dvv Nov 3, 2012

Contributor

still can't figure what rule would allow me to map GET /index.html onto some filepath w/o use of file... :)

Contributor

dvv commented Nov 3, 2012

still can't figure what rule would allow me to map GET /index.html onto some filepath w/o use of file... :)

@essen

This comment has been minimized.

Show comment Hide comment
@essen

essen Nov 3, 2012

Member

You are supposed to use file.

Member

essen commented Nov 3, 2012

You are supposed to use file.

@essen

This comment has been minimized.

Show comment Hide comment
@essen

essen Nov 27, 2012

Member

Hm for the path_info issue I don't think undefined is wrong. There is a path_info only if you specify '...', otherwise it is undefined. Makes sense to me.

Closing this if it's all good, please reopen if needed.

Member

essen commented Nov 27, 2012

Hm for the path_info issue I don't think undefined is wrong. There is a path_info only if you specify '...', otherwise it is undefined. Makes sense to me.

Closing this if it's all good, please reopen if needed.

@essen essen closed this Nov 27, 2012

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment