]> granicus.if.org Git - ejabberd/commitdiff
More fix in mod_http_fileserver to log URLs with/out query elements (#2021)
authorBadlop <badlop@process-one.net>
Fri, 6 Oct 2017 11:15:47 +0000 (13:15 +0200)
committerBadlop <badlop@process-one.net>
Fri, 6 Oct 2017 11:16:13 +0000 (13:16 +0200)
src/mod_http_fileserver.erl

index 73423d6a7644c231a4ffee9fa2a13baeb919c898..f34936724074f04ce75917a6b750ae5d7d834284 100644 (file)
@@ -436,7 +436,7 @@ add_to_log(File, FileSize, Code, Request) ->
     IP = ip_to_string(element(1, Request#request.ip)),
     Path = join(Request#request.path, "/"),
     Query = case stringify_query(Request#request.q) of
-               [] ->
+               <<"">> ->
                    "";
                String ->
                    [$? | String]
@@ -456,11 +456,13 @@ add_to_log(File, FileSize, Code, Request) ->
                FileSize, Referer, UserAgent]).
 
 stringify_query(Q) ->
-    join(
-       lists:map(fun(E) ->
-               lists:concat([binary_to_list(element(1, E)), "=", binary_to_list(element(2, E))])
-           end, Q),
-       "&").
+    stringify_query(Q, []).
+stringify_query([], Res) ->
+    join(lists:reverse(Res), "&");
+stringify_query([{nokey, _B} | Q], Res) ->
+    stringify_query(Q, Res);
+stringify_query([{A, B} | Q], Res) ->
+    stringify_query(Q, [join([A,B], "=") | Res]).
 
 find_header(Header, Headers, Default) ->
     case lists:keysearch(Header, 1, Headers) of