aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorPaweł Chmielowski <pchmielowski@process-one.net>2020-03-26 14:17:48 +0100
committerPaweł Chmielowski <pchmielowski@process-one.net>2020-03-26 14:17:48 +0100
commit5ec214386e3141e000fbcfaa53928c48f132c8fe (patch)
tree90fe4c650606ce6b53c7f59bb8ea89b617f4c0ba /src
parentRevert "Pass base path instead of level to support URL missing slash (#3177)" (diff)
Make webadmin redirect to page that end with /
Diffstat (limited to 'src')
-rw-r--r--src/ejabberd_http.erl9
-rw-r--r--src/ejabberd_web_admin.erl18
2 files changed, 21 insertions, 6 deletions
diff --git a/src/ejabberd_http.erl b/src/ejabberd_http.erl
index fad51f44f..83b6effda 100644
--- a/src/ejabberd_http.erl
+++ b/src/ejabberd_http.erl
@@ -386,7 +386,7 @@ extract_path_query(#state{request_method = Method,
{'EXIT', _Reason} -> [];
LQ -> LQ
end,
- {State, {LPath, LQuery, <<"">>}}
+ {State, {LPath, LQuery, <<"">>, Path}}
end;
extract_path_query(#state{request_method = Method,
request_path = {abs_path, Path},
@@ -402,7 +402,7 @@ extract_path_query(#state{request_method = Method,
{LPath, _Query} ->
case Method of
'PUT' ->
- {State, {LPath, [], Trail}};
+ {State, {LPath, [], Trail, Path}};
'POST' ->
case recv_data(State) of
{ok, Data} ->
@@ -410,7 +410,7 @@ extract_path_query(#state{request_method = Method,
{'EXIT', _Reason} -> [];
LQ -> LQ
end,
- {State, {LPath, LQuery, Data}};
+ {State, {LPath, LQuery, Data, Path}};
error ->
{State, false}
end
@@ -451,7 +451,7 @@ process_request(#state{request_method = Method,
case extract_path_query(State) of
{State2, false} ->
{State2, make_bad_request(State)};
- {State2, {LPath, LQuery, Data}} ->
+ {State2, {LPath, LQuery, Data, RawPath}} ->
PeerName = case SockPeer of
none ->
case SockMod of
@@ -471,6 +471,7 @@ process_request(#state{request_method = Method,
IP = analyze_ip_xff(IPHere, XFF),
Request = #request{method = Method,
path = LPath,
+ raw_path = RawPath,
q = LQuery,
auth = Auth,
length = Length,
diff --git a/src/ejabberd_web_admin.erl b/src/ejabberd_web_admin.erl
index 597dd06b0..b5bc4b15a 100644
--- a/src/ejabberd_web_admin.erl
+++ b/src/ejabberd_web_admin.erl
@@ -150,7 +150,21 @@ url_to_path(URL) -> str:tokens(URL, <<"/">>).
%%%==================================
%%%% process/2
-process([<<"server">>, SHost | RPath] = Path,
+process(Path, #request{raw_path = RawPath} = Request) ->
+ Continue = case Path of
+ [E] ->
+ binary:match(E, <<".">>) /= nomatch;
+ _ ->
+ false
+ end,
+ case Continue orelse binary:at(RawPath, size(RawPath) - 1) == $/ of
+ true ->
+ process2(Path, Request);
+ _ ->
+ {301, [{<<"Location">>, <<RawPath/binary, "/">>}], <<>>}
+ end.
+
+process2([<<"server">>, SHost | RPath] = Path,
#request{auth = Auth, lang = Lang, host = HostHTTP,
method = Method} =
Request) ->
@@ -185,7 +199,7 @@ process([<<"server">>, SHost | RPath] = Path,
end;
false -> ejabberd_web:error(not_found)
end;
-process(RPath,
+process2(RPath,
#request{auth = Auth, lang = Lang, host = HostHTTP,
method = Method} =
Request) ->