| 
						 
							
							
							
						 
					 | 
				
			
			 | 
			 | 
			
				@ -1,426 +0,0 @@
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				diff -r 0c4b60ac68b4 src/webmachine_dispatcher.erl
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				--- a/src/webmachine_dispatcher.erl	Tue Jun 15 08:36:55 2010 -0400
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				+++ b/src/webmachine_dispatcher.erl	Thu Sep 09 18:48:27 2010 +0100
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				@@ -22,7 +22,6 @@
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				 -author('Bryan Fink <bryan@basho.com>').
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				 
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				 -export([dispatch/2, dispatch/3]).
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				--include_lib("eunit/include/eunit.hrl").
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				 
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				 -define(SEPARATOR, $\/).
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				 -define(MATCH_ALL, '*').
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				@@ -203,194 +202,3 @@
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				 calculate_app_root(N) when N > 1 ->
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				     string:join(lists:duplicate(N, ".."), [?SEPARATOR]).
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				 
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				-%%
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				-%% TEST
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				-%%
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				-
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				-app_root_test() ->
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				-    ?assertEqual(".",           calculate_app_root(1)),
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				-    ?assertEqual("../..",       calculate_app_root(2)),
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				-    ?assertEqual("../../..",    calculate_app_root(3)),
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				-    ?assertEqual("../../../..", calculate_app_root(4)).
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				-
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				-reconstitute_test() ->
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				-    ?assertEqual("",            reconstitute([])),
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				-    ?assertEqual("foo",         reconstitute(["foo"])),
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				-    ?assertEqual("foo/bar",     reconstitute(["foo","bar"])),
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				-    ?assertEqual("foo/bar/baz", reconstitute(["foo","bar","baz"])).
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				-
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				-split_host_test() ->
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				-    ?assertEqual(["foo","bar","baz"], split_host("foo.bar.baz")).
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				-
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				-split_host_port_test() ->
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				-    ?assertEqual({[], 80}, split_host_port("")),
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				-    ?assertEqual({["foo","bar","baz"], 80},
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				-                 split_host_port("foo.bar.baz:80")),
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				-    ?assertEqual({["foo","bar","baz"], 1234},
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				-                 split_host_port("foo.bar.baz:1234")).
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				-
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				-%% port binding
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				-bind_port_simple_match_test() ->
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				-    ?assertEqual({ok, []}, bind_port(80, 80, [])),
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				-    ?assertEqual({ok, [{foo, bar}]},
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				-                 bind_port(1234, 1234, [{foo, bar}])).
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				-
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				-bind_port_matchall_test() ->
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				-    ?assertEqual({ok, []}, bind_port('*', 80, [])),
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				-    ?assertEqual({ok, [{foo, bar}]},
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				-                 bind_port('*', 1234, [{foo, bar}])).
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				-
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				-bind_port_match_test() ->
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				-    ?assertEqual({ok, [{foo, 80}]}, bind_port(foo, 80, [])),
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				-    {ok, WholeBinding} = bind_port(foo, 1234, [{bar, baz}]),
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				-    ?assertEqual(2, length(WholeBinding)),
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				-    ?assertEqual(1234, proplists:get_value(foo, WholeBinding)),
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				-    ?assertEqual(baz, proplists:get_value(bar, WholeBinding)).
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				-
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				-ind_port_fail_test() ->
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				-    ?assertEqual(fail, bind_port(80, 1234, [])).
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				-
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				-%% path binding
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				-
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				-bind_path_empty_test() ->
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				-    ?assertEqual({ok, [], [], 0}, bind([], [], [], 0)),
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				-    ?assertEqual({ok, [], [{x,"a"}], 1},
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				-                 bind([], [], [{x,"a"}], 1)).
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				-
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				-bind_path_matchall_test() ->
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				-    ?assertEqual({ok, [], [], 1},
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				-                 bind(['*'], [], [], 1)),
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				-    ?assertEqual({ok, ["a","b"], [], 2},
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				-                 bind(['*'], ["a","b"], [], 0)).
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				-
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				-bind_path_fail_longer_match_test() ->
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				-    ?assertEqual(fail, bind(["x"], [], [], 0)),
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				-    ?assertEqual(fail, bind([foo], [], [], 0)).
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				-
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				-bind_path_with_binding_test() ->
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				-    ?assertEqual({ok, [], [{foo, "a"}], 1},
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				-                 bind([foo], ["a"], [], 0)),
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				-    {ok, Rest, Bind, Depth} = bind([foo,'*'], ["a","b"], [{bar, baz}], 1),
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				-    ?assertEqual(["b"], Rest),
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				-    ?assertEqual(3, Depth),
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				-    ?assertEqual(2, length(Bind)),
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				-    ?assertEqual("a", proplists:get_value(foo, Bind)),
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				-    ?assertEqual(baz, proplists:get_value(bar, Bind)).
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				-
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				-bind_path_string_match_test() ->
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				-    ?assertEqual({ok, [], [], 1},
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				-                 bind(["a"], ["a"], [], 0)),
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				-    ?assertEqual({ok, [], [{foo, bar}], 4},
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				-                 bind(["a","b","c"], ["a","b","c"], [{foo, bar}], 1)).
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				-
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				-bind_path_string_fail_test() ->
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				-    ?assertEqual(fail, bind(["a"], ["b"], [], 0)),
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				-    ?assertEqual(fail, bind(["a","b"], ["a","c"], [], 0)).
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				-
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				-try_path_matching_test() ->
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				-    ?assertEqual({bar, baz, [], [], ".", ""},
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				-                 try_path_binding([{["foo"], bar, baz}], ["foo"], [], 0)),
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				-    Dispatch = [{["a", x], foo, bar},
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				-                {["b", y], baz, quux},
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				-                {["b", y, '*'], baz2, quux2}],
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				-    ?assertEqual({foo, bar, [], [{x, "c"}], "../..", []},
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				-                 try_path_binding(Dispatch, ["a","c"], [], 0)),
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				-    ?assertEqual({baz, quux, [], [{y, "c"}], "../..", []},
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				-                 try_path_binding(Dispatch, ["b","c"], [], 0)),
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				-    ?assertEqual({baz2, quux2, ["z"], [{y, "c"}], "../../..", "z"},
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				-                 try_path_binding(Dispatch, ["b","c","z"], [], 0)),
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				-    ?assertEqual({baz2, quux2, ["z","v"], [{y, "c"}], "../../../..", "z/v"},
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				-                 try_path_binding(Dispatch, ["b","c","z","v"], [], 0)).
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				-
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				-try_path_failing_test() ->
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				-    ?assertEqual({no_dispatch_match, ["a"]},
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				-                 try_path_binding([{["b"], x, y}], ["a"], [], 0)).
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				-
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				-%% host binding
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				-
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				-try_host_binding_nohosts_test() ->
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				-    PathDispatches = [{["a"], foo, bar},
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				-                      {["b"], baz, quux}],
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				-    ?assertEqual(try_host_binding([{{['*'],'*'},PathDispatches}],
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				-                                  ["quux","baz"], 80, ["a"], 0),
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				-                 try_host_binding(PathDispatches,
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				-                                  ["quux","baz"], 80, ["a"], 0)),
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				-    ?assertEqual(try_host_binding([{{['*'],'*'},PathDispatches}],
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				-                                  ["quux","baz"], 80, ["b"], 0),
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				-                 try_host_binding(PathDispatches,
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				-                                  ["quux","baz"], 80, ["b"], 0)),
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				-    ?assertEqual(try_host_binding([ {{['*'],'*'},[D]} || D <- PathDispatches],
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				-                                  ["quux","baz"], 1234, ["a"], 0),
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				-                 try_host_binding(PathDispatches,
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				-                                  ["quux","baz"], 1234, ["a"], 0)),
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				-    ?assertEqual(try_host_binding([ {{['*'],'*'},[D]} || D <- PathDispatches],
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				-                                  ["quux","baz"], 1234, ["b"], 0),
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				-                 try_host_binding(PathDispatches,
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				-                                  ["quux","baz"], 1234, ["b"], 0)).
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				-
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				-try_host_binding_noport_test() ->
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				-    Dispatch = [{["foo","bar"], [{["a"],x,y}]},
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				-                {["baz","quux"],[{["b"],z,q}]},
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				-                {[m,"quux"],    [{["c"],r,s}]},
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				-                {['*',"quux"],  [{["d"],t,u}]}],
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				-    ExplicitWildPort = [ {{H, '*'},P} || {H, P} <- Dispatch ],
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				-    ?assertEqual(try_host_binding(ExplicitWildPort,
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				-                                  ["bar","foo"], 80, ["a"], 0),
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				-                 try_host_binding(Dispatch,
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				-                                  ["bar","foo"], 80, ["a"], 0)),
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				-    ?assertEqual(try_host_binding(ExplicitWildPort,
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				-                                  ["quux","baz"], 1234, ["b"], 0),
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				-                 try_host_binding(Dispatch,
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				-                                  ["quux","baz"], 1234, ["b"], 0)),
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				-    ?assertEqual(try_host_binding(ExplicitWildPort,
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				-                                  ["quux","yes"], 81, ["c"], 0),
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				-                 try_host_binding(Dispatch,
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				-                                  ["quux","yes"], 81, ["c"], 0)),
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				-    ?assertEqual(try_host_binding(ExplicitWildPort,
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				-                                  ["quux","no"], 82, ["d"], 0),
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				-                 try_host_binding(Dispatch,
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				-                                  ["quux","no"], 82, ["d"], 0)).
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				-
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				-try_host_binding_fullmatch_test() ->
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				-    Dispatch = [{{["foo","bar"],80},[{["a"],x,y}]},
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				-                {{[foo,"bar"],80},  [{["b"],z,q}]},
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				-                {{[foo,"bar"],baz}, [{["c"],r,s}]},
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				-                {{['*',"bar"],'*'}, [{["d"],t,u}]}],
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				-    ?assertEqual({x, y, [], 80, [], [], ".", ""},
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				-                 try_host_binding(Dispatch,
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				-                                  ["bar","foo"], 80, ["a"], 0)),
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				-    ?assertEqual({z, q, [], 80, [], [{foo,"baz"}], ".", ""},
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				-                 try_host_binding(Dispatch,
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				-                                  ["bar","baz"], 80, ["b"], 0)),
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				-    {Mod, Props, HostRemainder, Port, PathRemainder,
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				-     PathBindings, AppRoot, StringPath}=
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				-        try_host_binding(Dispatch, ["bar","quux"], 1234, ["c"], 0),
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				-    ?assertEqual(r, Mod),
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				-    ?assertEqual(s, Props),
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				-    ?assertEqual("", HostRemainder),
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				-    ?assertEqual(1234, Port),
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				-    ?assertEqual([], PathRemainder),
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				-    ?assertEqual(2, length(PathBindings)),
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				-    ?assertEqual("quux", proplists:get_value(foo, PathBindings)),
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				-    ?assertEqual(1234, proplists:get_value(baz, PathBindings)),
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				-    ?assertEqual(".", AppRoot),
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				-    ?assertEqual("", StringPath),
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				-    ?assertEqual({t, u, ["quux","foo"], 80, [], [], ".", ""},
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				-                 try_host_binding(Dispatch, ["bar","quux","foo"],80,["d"],0)).
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				-
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				-try_host_binding_fail_test() ->
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				-    ?assertEqual({no_dispatch_match, {["bar","foo"], 1234}, ["x","y","z"]},
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				-                 try_host_binding([], ["bar","foo"], 1234, ["x","y","z"], 0)).
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				-
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				-dispatch_test() ->
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				-    ?assertEqual({x, y, [], 80, [], [], "../../..", ""},
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				-                 dispatch("a/b/c",[{["a","b","c"],x,y}])),
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				-    ?assertEqual({x, y, [], 80, [], [], "../../..", ""},
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				-                 dispatch("foo.bar", "a/b/c",
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				-                          [{{["foo","bar"],80},[{["a","b","c"],x,y}]}])),
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				-    ?assertEqual({x, y, [], 1234, [], [], "../../..", ""},
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				-                 dispatch("foo.bar:1234", "a/b/",
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				-                          [{{["foo","bar"],1234},[{["a","b"],x,y}]}])),
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				-    ?assertEqual({no_dispatch_match, {["bar","baz"],8000}, ["q","r"]},
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				-                 dispatch("baz.bar:8000", "q/r",
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				-                          [{{["foo","bar"],80},[{["a","b","c"],x,y}]}])).
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				diff -r 0c4b60ac68b4 src/webmachine_multipart.erl
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				--- a/src/webmachine_multipart.erl	Tue Jun 15 08:36:55 2010 -0400
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				+++ b/src/webmachine_multipart.erl	Thu Sep 09 18:48:27 2010 +0100
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				@@ -21,7 +21,6 @@
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				 -author('Andy Gross <andy@basho.com>').
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				 -export([get_all_parts/2,stream_parts/2, find_boundary/1]).
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				 
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				--include_lib("eunit/include/eunit.hrl").
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				 
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				 % @type incoming_req_body() = binary().
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				 % The request body, in "multipart/form-data" (rfc2388) form,
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				@@ -143,31 +142,3 @@
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				             {Body, done}
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				     end.
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				 
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				-body_test() ->
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				-    Body = <<"------------ae0gL6gL6Ij5KM7Ef1KM7ei4ae0cH2\r\nContent-Disposition: form-data; name=\"Filename\"\r\n\r\ntestfile.txt\r\n------------ae0gL6gL6Ij5KM7Ef1KM7ei4ae0cH2\r\nContent-Disposition: form-data; name=\"Filedata\"; filename=\"testfile.txt\"\r\nContent-Type: application/octet-stream\r\n\r\n%%% The contents of this file are a test,\n%%% do not be alarmed.\n\r\n------------ae0gL6gL6Ij5KM7Ef1KM7ei4ae0cH2\r\nContent-Disposition: form-data; name=\"Upload\"\r\n\r\nSubmit Query\r\n------------ae0gL6gL6Ij5KM7Ef1KM7ei4ae0cH2--">>,
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				-    Boundary = "----------ae0gL6gL6Ij5KM7Ef1KM7ei4ae0cH2",
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				-    ?assertEqual(
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				-       [{"Filename",
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				-         {[{<<"name">>,<<"Filename">>}],[]},
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				-         <<"testfile.txt\r\n">>},
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				-        {"Filedata",
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				-         {[{<<"name">>,<<"Filedata">>},
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				-           {<<"filename">>,<<"testfile.txt">>}],
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				-          [{<<"Content-Type">>,<<"application/octet-stream">>}]},
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				-         <<"%%% The contents of this file are a test,\n%%% do not be alarmed.\n\r\n">>},
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				-        {"Upload",
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				-         {[{<<"name">>,<<"Upload">>}],[]},
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				-         <<"Submit Query\r\n">>}],
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				-       get_all_parts(Body, Boundary)).
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				-    
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				-body2_test() ->
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				-    Body = <<"-----------------------------89205314411538515011004844897\r\nContent-Disposition: form-data; name=\"Filedata\"; filename=\"akamai.txt\"\r\nContent-Type: text/plain\r\n\r\nCAMBRIDGE, MA - February 18, 2009 - Akamai Technologies, Inc. (NASDAQ: AKAM), the leader in powering rich media, dynamic transactions and enterprise applications online, today announced that its Service & Support organization was awarded top honors for Innovation in Customer Service at the 3rd Annual Stevie Awards for Sales & Customer Service, an international competition recognizing excellence in disciplines that are crucial to business success.\n\n\"We have always set incredibly high standards with respect to the service and support we provide our customers,\" said Sanjay Singh, vice president of Global Service & Support at Akamai. \"Our support team provides highly responsive service around the clock to our global customer base and, as a result, has become an extension of our customers' online businesses. This prestigious award is validation of Akamai's commitment to customer service and technical support.\"\n\nAkamai Service & Support professionals are dedicated to working with customers on a daily basis to fine tune, optimize, and support their Internet initiatives. Akamai's winning submission highlighted the key pillars of its service and support offering, as well as the initiatives established to meet customer requirements for proactive communication, simplification, and faster response times.\n\n\"This year's honorees demonstrate that even in challenging economic times, it's possible for organizations to continue to shine in sales and customer service, the two most important functions in business: acquiring and keeping customers,\" said Michael Gallagher, president of the Stevie Awards.\n\nThe awards are presented by the Stevie Awards, which organizes several of the world's leading business awards shows, including the prestigious American Business Awards. Nicknamed the Stevies for the Greek word \"crowned,\" winners were announced during a gala banquet on Monday, February 9 at Caesars Palace in Las Vegas. Nominated customer service and sales executives from the U.S.A. and several other countries attended. More than 500 entries from companies of all sizes and in virtually every industry were submitted to this year's competition. There are 27 categories for customer service professionals, as well as 41 categories for sales professionals.\n\nDetails about the Stevie Awards for Sales & Customer Service and the list of honorees in all categories are available at www.stevieawards.com/sales. \n\r\n-----------------------------89205314411538515011004844897--\r\n">>,
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				-    Boundary = "---------------------------89205314411538515011004844897",
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				-    ?assertEqual(
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				-       [{"Filedata",
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				-         {[{<<"name">>,<<"Filedata">>},
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				-           {<<"filename">>,<<"akamai.txt">>}],
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				-          [{<<"Content-Type">>,<<"text/plain">>}]},
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				-         <<"CAMBRIDGE, MA - February 18, 2009 - Akamai Technologies, Inc. (NASDAQ: AKAM), the leader in powering rich media, dynamic transactions and enterprise applications online, today announced that its Service & Support organization was awarded top honors for Innovation in Customer Service at the 3rd Annual Stevie Awards for Sales & Customer Service, an international competition recognizing excellence in disciplines that are crucial to business success.\n\n\"We have always set incredibly high standards with respect to the service and support we provide our customers,\" said Sanjay Singh, vice president of Global Service & Support at Akamai. \"Our support team provides highly responsive service around the clock to our global customer base and, as a result, has become an extension of our customers' online businesses. This prestigious award is validation of Akamai's commitment to customer service and technical support.\"\n\nAkamai Service & Support professionals are dedicated to working with customers on a daily basis to fine tune, optimize, and support their Internet initiatives. Akamai's winning submission highlighted the key pillars of its service and support offering, as well as the initiatives established to meet customer requirements for proactive communication, simplification, and faster response times.\n\n\"This year's honorees demonstrate that even in challenging economic times, it's possible for organizations to continue to shine in sales and customer service, the two most important functions in business: acquiring and keeping customers,\" said Michael Gallagher, president of the Stevie Awards.\n\nThe awards are presented by the Stevie Awards, which organizes several of the world's leading business awards shows, including the prestigious American Business Awards. Nicknamed the Stevies for the Greek word \"crowned,\" winners were announced during a gala banquet on Monday, February 9 at Caesars Palace in Las Vegas. Nominated customer service and sales executives from the U.S.A. and several other countries attended. More than 500 entries from companies of all sizes and in virtually every industry were submitted to this year's competition. There are 27 categories for customer service professionals, as well as 41 categories for sales professionals.\n\nDetails about the Stevie Awards for Sales & Customer Service and the list of honorees in all categories are available at www.stevieawards.com/sales. \n\r\n">>
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				-        }],
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				-       get_all_parts(Body,Boundary)).
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				diff -r 0c4b60ac68b4 src/webmachine_router.erl
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				--- a/src/webmachine_router.erl	Tue Jun 15 08:36:55 2010 -0400
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				+++ b/src/webmachine_router.erl	Thu Sep 09 18:48:27 2010 +0100
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				@@ -19,7 +19,6 @@
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				 %%      the table each time webmachine restarts.
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				 -module(webmachine_router).
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				 
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				--include_lib("eunit/include/eunit.hrl").
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				 
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				 -behaviour(gen_server).
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				 
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				@@ -148,42 +147,3 @@
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				     ok = application:set_env(webmachine, dispatch_list, DispatchList),
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				     ok.
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				 
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				-%% For unit tests only
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				-start() ->
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				-    gen_server:start({local, ?SERVER}, ?MODULE, [], []).
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				-
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				-get_routes() ->
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				-    gen_server:call(?SERVER, get_routes).
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				-
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				-%% Tests
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				-add_remove_route_test() ->
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				-    application:set_env(webmachine, dispatch_list, []),
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				-    {ok, Pid} = start(),
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				-    PathSpec = {["foo"], foo, []},
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				-    webmachine_router:add_route(PathSpec),
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				-    [PathSpec] = get_routes(),
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				-    webmachine_router:remove_route(PathSpec),
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				-    [] = get_routes(),
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				-    exit(Pid, kill).
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				-
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				-add_remove_resource_test() ->
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				-    application:set_env(webmachine, dispatch_list, []),
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				-    {ok, Pid} = start(),
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				-    PathSpec1 = {["foo"], foo, []},
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				-    PathSpec2 = {["bar"], foo, []},
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				-    PathSpec3 = {["baz"], bar, []},
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				-    webmachine_router:add_route(PathSpec1),
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				-    webmachine_router:add_route(PathSpec2),
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				-    webmachine_router:add_route(PathSpec3),
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				-    webmachine_router:remove_resource(foo),
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				-    [PathSpec3] = get_routes(),
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				-    exit(Pid, kill).
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				-
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				-no_dupe_path_test() ->
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				-    application:set_env(webmachine, dispatch_list, []),
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				-    {ok, Pid} = start(),
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				-    PathSpec = {["foo"], foo, []},
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				-    webmachine_router:add_route(PathSpec),
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				-    webmachine_router:add_route(PathSpec),
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				-    [PathSpec] = get_routes(),
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				-    exit(Pid, kill).
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				diff -r 0c4b60ac68b4 src/webmachine_util.erl
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				--- a/src/webmachine_util.erl	Tue Jun 15 08:36:55 2010 -0400
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				+++ b/src/webmachine_util.erl	Thu Sep 09 18:48:27 2010 +0100
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				@@ -27,8 +27,6 @@
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				 -export([now_diff_milliseconds/2]).
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				 -export([media_type_to_detail/1]).
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				 
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				--include_lib("eunit/include/eunit.hrl").
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				-
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				 convert_request_date(Date) ->
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				     try 
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				 	case httpd_util:convert_request_date(Date) of
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				@@ -295,65 +293,3 @@
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				 now_diff_milliseconds({M,S,U}, {M1,S1,U1}) ->
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				     ((M-M1)*1000000+(S-S1))*1000 + ((U-U1) div 1000).
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				 
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				-%%
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				-%% TEST
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				-%%
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				-
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				-choose_media_type_test() ->
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				-    Provided = "text/html",
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				-    ShouldMatch = ["*", "*/*", "text/*", "text/html"],
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				-    WantNone = ["foo", "text/xml", "application/*", "foo/bar/baz"],
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				-    [ ?assertEqual(Provided, choose_media_type([Provided], I))
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				-      || I <- ShouldMatch ],
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				-    [ ?assertEqual(none, choose_media_type([Provided], I))
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				-      || I <- WantNone ].
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				-
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				-choose_media_type_qval_test() ->
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				-    Provided = ["text/html", "image/jpeg"],
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				-    HtmlMatch = ["image/jpeg;q=0.5, text/html",
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				-                 "text/html, image/jpeg; q=0.5",
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				-                 "text/*; q=0.8, image/*;q=0.7",
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				-                 "text/*;q=.8, image/*;q=.7"], %% strange FeedBurner format
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				-    JpgMatch = ["image/*;q=1, text/html;q=0.9",
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				-                "image/png, image/*;q=0.3"],
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				-    [ ?assertEqual("text/html", choose_media_type(Provided, I))
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				-      || I <- HtmlMatch ],
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				-    [ ?assertEqual("image/jpeg", choose_media_type(Provided, I))
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				-      || I <- JpgMatch ].
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				-
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				-convert_request_date_test() ->
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				-    ?assertMatch({{_,_,_},{_,_,_}},
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				-                 convert_request_date("Wed, 30 Dec 2009 14:39:02 GMT")),
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				-    ?assertMatch(bad_date,
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				-                 convert_request_date(<<"does not handle binaries">>)).
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				-
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				-compare_ims_dates_test() ->
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				-    Late = {{2009,12,30},{14,39,02}},
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				-    Early = {{2009,12,30},{13,39,02}},
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				-    ?assertEqual(true, compare_ims_dates(Late, Early)),
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				-    ?assertEqual(false, compare_ims_dates(Early, Late)).
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				-
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				-guess_mime_test() ->
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				-    TextTypes = [".html",".css",".htc",".manifest",".txt"],
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				-    AppTypes = [".xhtml",".xml",".js",".swf",".zip",".bz2",
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				-                ".gz",".tar",".tgz"],
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				-    ImgTypes = [".jpg",".jpeg",".gif",".png",".ico",".svg"],
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				-    ?assertEqual([], [ T || T <- TextTypes,
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				-                            1 /= string:str(guess_mime(T),"text/") ]),
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				-    ?assertEqual([], [ T || T <- AppTypes,
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				-                            1 /= string:str(guess_mime(T),"application/") ]),
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				-    ?assertEqual([], [ T || T <- ImgTypes,
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				-                            1 /= string:str(guess_mime(T),"image/") ]).
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				-
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				-unquote_header_test() ->
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				-    ?assertEqual("hello", unquote_header("hello")),
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				-    ?assertEqual("hello", unquote_header("\"hello\"")),
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				-    ?assertEqual("hello", unquote_header("\"hello")),
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				-    ?assertEqual("hello", unquote_header("\"\\h\\e\\l\\l\\o\"")).
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				-
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				-now_diff_milliseconds_test() ->
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				-    Late = {10, 10, 10},
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				-    Early1 = {10, 9, 9},
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				-    Early2 = {9, 9, 9},
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				-    ?assertEqual(1000, now_diff_milliseconds(Late, Early1)),
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				-    ?assertEqual(1000001000, now_diff_milliseconds(Late, Early2)).
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				diff -r 0c4b60ac68b4 src/wrq.erl
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				--- a/src/wrq.erl	Tue Jun 15 08:36:55 2010 -0400
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				+++ b/src/wrq.erl	Thu Sep 09 18:48:27 2010 +0100
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				@@ -32,7 +32,6 @@
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				 % @type reqdata(). The opaque data type used for req/resp data structures.
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				 -include_lib("include/wm_reqdata.hrl").
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				 -include_lib("include/wm_reqstate.hrl").
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				--include_lib("eunit/include/eunit.hrl").
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				 
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				 
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				 create(Method,Version,RawPath,Headers) ->
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				@@ -210,33 +209,3 @@
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				 make_wrq(Method, RawPath, Headers) ->
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				     create(Method, {1,1}, RawPath, mochiweb_headers:from_list(Headers)).
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				 
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				-accessor_test() ->
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				-    R0 = make_wrq('GET', "/foo?a=1&b=2", [{"Cookie", "foo=bar"}]),
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				-    R = set_peer("127.0.0.1", R0),
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				-    ?assertEqual('GET', method(R)),
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				-    ?assertEqual({1,1}, version(R)),
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				-    ?assertEqual("/foo", path(R)),
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				-    ?assertEqual("/foo?a=1&b=2", raw_path(R)),     
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				-    ?assertEqual([{"a", "1"}, {"b", "2"}], req_qs(R)),
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				-    ?assertEqual({"1", "2"}, {get_qs_value("a", R), get_qs_value("b", R)}),
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				-    ?assertEqual("3", get_qs_value("c", "3", R)),
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				-    ?assertEqual([{"foo", "bar"}], req_cookie(R)),
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				-    ?assertEqual("bar", get_cookie_value("foo", R)),
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				-    ?assertEqual("127.0.0.1", peer(R)).
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				-
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				-    
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				-simple_dispatch_test() ->
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				-    R0 = make_wrq('GET', "/foo?a=1&b=2", [{"Cookie", "foo=bar"}]),
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				-    R1 = set_peer("127.0.0.1", R0),    
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				-    {_, _, HostTokens, Port, PathTokens, Bindings, AppRoot, StringPath} = 
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				-        webmachine_dispatcher:dispatch("127.0.0.1", "/foo", 
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				-                                       [{["foo"], foo_resource, []}]),
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				-    R = load_dispatch_data(Bindings,
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				-                           HostTokens,
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				-                           Port,
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				-                           PathTokens,
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				-                           AppRoot,
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				-                           StringPath,
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				-                           R1),
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				-    ?assertEqual(".", app_root(R)),
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				-    ?assertEqual(80, port(R)).
 |