24
1
mirror of https://github.com/processone/ejabberd.git synced 2024-06-12 21:52:07 +02:00

Accept routes in Host header and map them to vhosts

This commit is contained in:
Evgeniy Khramtsov 2017-10-05 10:26:10 +03:00
parent 9e95150803
commit bd06bc00e2

View File

@ -178,10 +178,15 @@ check_docroot_defined(DocRoot, Host) ->
end. end.
check_docroot_exists(DocRoot) -> check_docroot_exists(DocRoot) ->
case file:read_file_info(DocRoot) of case filelib:ensure_dir(filename:join(DocRoot, "foo")) of
{error, Reason} -> ok ->
throw({error_access_docroot, DocRoot, Reason}); case file:read_file_info(DocRoot) of
{ok, FI} -> FI {error, Reason} ->
throw({error_access_docroot, DocRoot, Reason});
{ok, FI} -> FI
end;
{error, Reason} ->
throw({error_access_docroot, DocRoot, Reason})
end. end.
check_docroot_is_dir(DRInfo, DocRoot) -> check_docroot_is_dir(DRInfo, DocRoot) ->
@ -297,18 +302,20 @@ code_change(_OldVsn, State, _Extra) ->
%% Returns the page to be sent back to the client and/or HTTP status code. %% Returns the page to be sent back to the client and/or HTTP status code.
process(LocalPath, #request{host = Host, auth = Auth, headers = RHeaders} = Request) -> process(LocalPath, #request{host = Host, auth = Auth, headers = RHeaders} = Request) ->
?DEBUG("Requested ~p", [LocalPath]), ?DEBUG("Requested ~p", [LocalPath]),
try gen_server:call(get_proc_name(Host), {serve, LocalPath, Auth, RHeaders}) of try
{FileSize, Code, Headers, Contents} -> VHost = ejabberd_router:host_of_route(Host),
add_to_log(FileSize, Code, Request), {FileSize, Code, Headers, Contents} =
{Code, Headers, Contents} gen_server:call(get_proc_name(VHost),
catch {serve, LocalPath, Auth, RHeaders}),
exit:{noproc, _} -> add_to_log(FileSize, Code, Request#request{host = VHost}),
?ERROR_MSG("Received an HTTP request with Host ~p, but couldn't find the related " {Code, Headers, Contents}
"ejabberd virtual host", [Request#request.host]), catch _:{Why, _} when Why == noproc; Why == invalid_domain; Why == unregistered_route ->
?ERROR_MSG("Received an HTTP request with Host: ~s, "
"but couldn't find the related "
"ejabberd virtual host", [Host]),
ejabberd_web:error(not_found) ejabberd_web:error(not_found)
end. end.
serve(LocalPath, Auth, DocRoot, DirectoryIndices, CustomHeaders, DefaultContentType, serve(LocalPath, Auth, DocRoot, DirectoryIndices, CustomHeaders, DefaultContentType,
ContentTypes, UserAccess, IfModifiedSince) -> ContentTypes, UserAccess, IfModifiedSince) ->
CanProceed = case {UserAccess, Auth} of CanProceed = case {UserAccess, Auth} of