From 0ca8f1364b857632030dbc3735ce789686361073 Mon Sep 17 00:00:00 2001 From: Anthony Ramine Date: Mon, 9 May 2011 14:31:06 +0200 Subject: Implement path_info feature The dispatcher now accepts '...' as the leading segment of Host and the trailing segment of Path, this special atom matches any remaining path tail. When given "cowboy.bugs.dev-extend.eu", host rule ['...', <<"dev-extend">>, <<"eu">>] matches and fills host_info with [<<"cowboy">>, <<"bugs">>]. When given "/a/b/c/d", path rule [<<"a">>, <<"b">>, '...'] matches and fills path_info with [<<"c">>, <<"d">>]. --- src/cowboy_http_protocol.erl | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'src/cowboy_http_protocol.erl') diff --git a/src/cowboy_http_protocol.erl b/src/cowboy_http_protocol.erl index 302df26..ed4d963 100644 --- a/src/cowboy_http_protocol.erl +++ b/src/cowboy_http_protocol.erl @@ -1,4 +1,5 @@ %% Copyright (c) 2011, Loïc Hoguin +%% Copyright (c) 2011, Anthony Ramine %% %% Permission to use, copy, modify, and/or distribute this software for any %% purpose with or without fee is hereby granted, provided that the above @@ -158,8 +159,9 @@ dispatch(Req=#http_req{host=Host, path=Path}, %% @todo We probably want to filter the Host and Path here to allow %% things like url rewriting. case cowboy_dispatcher:match(Host, Path, Dispatch) of - {ok, Handler, Opts, Binds} -> - parse_header(Req#http_req{bindings=Binds}, + {ok, Handler, Opts, Binds, HostInfo, PathInfo} -> + parse_header(Req#http_req{host_info=HostInfo, path_info=PathInfo, + bindings=Binds}, State#state{handler={Handler, Opts}}); {error, notfound, host} -> error_terminate(400, State); -- cgit v1.2.3