aboutsummaryrefslogtreecommitdiffstats
path: root/src/cowboy_http_req.erl
diff options
context:
space:
mode:
authorAnthony Ramine <[email protected]>2011-05-09 14:31:06 +0200
committerAnthony Ramine <[email protected]>2011-05-09 15:14:38 +0200
commit0ca8f1364b857632030dbc3735ce789686361073 (patch)
treeba2af89911ea808263913e27ebf227f18a2ad29c /src/cowboy_http_req.erl
parent094f5c1735f92bb13b3b02440f24781d37a393cb (diff)
downloadcowboy-0ca8f1364b857632030dbc3735ce789686361073.tar.gz
cowboy-0ca8f1364b857632030dbc3735ce789686361073.tar.bz2
cowboy-0ca8f1364b857632030dbc3735ce789686361073.zip
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">>].
Diffstat (limited to 'src/cowboy_http_req.erl')
-rw-r--r--src/cowboy_http_req.erl16
1 files changed, 14 insertions, 2 deletions
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}.