Skip to content

Commit

Permalink
Support override_host, default_host
Browse files Browse the repository at this point in the history
  • Loading branch information
tonyg committed Jun 12, 2010
1 parent 2833444 commit 5b6bd06
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 12 deletions.
8 changes: 4 additions & 4 deletions src/reflect_meta.erl
Expand Up @@ -4,9 +4,9 @@

-define(RPC_TIMEOUT, 10000).

handle(Req, _Config, AccessUrl, [], _QueryFields) ->
handle(Req, Config, AccessUrl, [], _QueryFields) ->
reply_with(Req, "Access Point",
gen_info(Req, AccessUrl) ++
gen_info(Req, Config, AccessUrl) ++
[{h2, <<"Registered Delegations">>},
{table, [{class, "meta-table"}],
[{tr, [], [{th, X} ||
Expand All @@ -15,10 +15,10 @@ handle(Req, _Config, AccessUrl, [], _QueryFields) ->
handle(Req, _Config, _AccessUrl, _PathComponents, _QueryFields) ->
Req:not_found().

gen_info(Req, AccessUrl) ->
gen_info(Req, Config, AccessUrl) ->
[{h2, <<"General Info">>},
{p, [<<"Access point info: ">>, hlink(AccessUrl)]},
{p, [<<"Site root: ">>, hlink("http://" ++ Req:get_header_value(host) ++ "/")]}].
{p, [<<"Site root: ">>, hlink("http://" ++ reversehttp:host(Req, Config) ++ "/")]}].

template(Title, BodyElts) ->
{html,
Expand Down
4 changes: 2 additions & 2 deletions src/reqparser_path.erl
Expand Up @@ -23,5 +23,5 @@ extract_label(Path) ->
{ok, string:left(Path, N - 1)}
end.

ext_url(Req, _Config, HostLabel) ->
"http://" ++ string:to_lower(Req:get_header_value(host)) ++ "/" ++ HostLabel ++ "/".
ext_url(Req, Config, HostLabel) ->
"http://" ++ string:to_lower(reversehttp:host(Req, Config)) ++ "/" ++ HostLabel ++ "/".
18 changes: 12 additions & 6 deletions src/reversehttp.erl
Expand Up @@ -6,7 +6,7 @@
-module(reversehttp).
-author('author <author@example.com>').
-export([start/0, stop/0]).
-export([lookup/2, lookup/3, match_access_point/2]).
-export([lookup/2, lookup/3, host/2, match_access_point/2]).

ensure_started(App) ->
case application:start(App) of
Expand Down Expand Up @@ -46,13 +46,19 @@ lookup(Key, AssocList, DefaultValue) ->
DefaultValue
end.

host(Req, Config) ->
case lookup(override_host, Config, undefined) of
undefined ->
case Req:get_header_value(host) of
undefined -> lookup(default_host, Config, "localhost");
V -> V
end;
V -> V
end.

match_access_point(Req, Config) ->
Host = case Req:get_header_value(host) of
undefined -> lookup(canonical_host, Config, "localhost");
V -> V
end,
match_access_point1(mochiweb_util:urlsplit_path(Req:get(raw_path)),
Host,
host(Req, Config),
lookup(access_point_paths, Config, [])).

match_access_point1({Path, _QueryPart, _Fragment}, _Host, []) ->
Expand Down

0 comments on commit 5b6bd06

Please sign in to comment.