Browse Source

Discard the port from the host before tokenizing it.

Loïc Hoguin 14 years ago
parent
commit
4cbba84a00
1 changed files with 6 additions and 1 deletions
  1. 6 1
      src/cowboy_dispatcher.erl

+ 6 - 1
src/cowboy_dispatcher.erl

@@ -22,7 +22,11 @@
 
 -spec split_host(Host::string()) -> Tokens::path_tokens().
 split_host(Host) ->
-	string:tokens(Host, ".").
+	Host2 = case string:chr(Host, $:) of
+		0 -> Host;
+		N -> lists:sublist(Host, N - 1)
+	end,
+	string:tokens(Host2, ".").
 
 -spec split_path(Path::string())
 	-> {Tokens::path_tokens(), Path::string(), Qs::string()}.
@@ -112,6 +116,7 @@ split_host_test_() ->
 		{"cowboy.dev-extend.eu", ["cowboy", "dev-extend", "eu"]},
 		{"dev-extend..eu", ["dev-extend", "eu"]},
 		{"dev-extend.eu", ["dev-extend", "eu"]},
+		{"dev-extend.eu:8080", ["dev-extend", "eu"]},
 		{"a.b.c.d.e.f.g.h.i.j.k.l.m.n.o.p.q.r.s.t.u.v.w.x.y.z",
 			["a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m",
 			 "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z"]}