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_req.erl | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) (limited to 'src/cowboy_http_req.erl') diff --git a/src/cowboy_http_req.erl b/src/cowboy_http_req.erl index 60f0b55..fad5aaf 100644 --- a/src/cowboy_http_req.erl +++ b/src/cowboy_http_req.erl @@ -17,8 +17,8 @@ -export([ method/1, version/1, peer/1, - host/1, raw_host/1, port/1, - path/1, raw_path/1, + host/1, host_info/1, raw_host/1, port/1, + path/1, path_info/1, raw_path/1, qs_val/2, qs_val/3, qs_vals/1, raw_qs/1, binding/2, binding/3, bindings/1, header/2, header/3, headers/1 @@ -59,6 +59,12 @@ peer(Req) -> host(Req) -> {Req#http_req.host, Req}. +-spec host_info(Req::#http_req{}) + -> {HostInfo::cowboy_dispatcher:path_tokens() | undefined, + Req::#http_req{}}. +host_info(Req) -> + {Req#http_req.host_info, Req}. + -spec raw_host(Req::#http_req{}) -> {RawHost::binary(), Req::#http_req{}}. raw_host(Req) -> {Req#http_req.raw_host, Req}. @@ -72,6 +78,12 @@ port(Req) -> path(Req) -> {Req#http_req.path, Req}. +-spec path_info(Req::#http_req{}) + -> {PathInfo::cowboy_dispatcher:path_tokens() | undefined, + Req::#http_req{}}. +path_info(Req) -> + {Req#http_req.path_info, Req}. + -spec raw_path(Req::#http_req{}) -> {RawPath::binary(), Req::#http_req{}}. raw_path(Req) -> {Req#http_req.raw_path, Req}. -- cgit v1.2.3