aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaweł Chmielowski <pchmielowski@process-one.net>2017-07-28 16:07:54 +0200
committerPaweł Chmielowski <pchmielowski@process-one.net>2017-07-28 16:08:05 +0200
commit51fa43834032f8d7a3c289be00213070809ce5b6 (patch)
treeda19bd6f4723ba5becbe935d414ce1c6f9440c59
parentRevert "Fix get_module_opt call in mod_block_strangers" (diff)
Request basic auth dialog from browser
-rw-r--r--src/mod_http_fileserver.erl16
1 files changed, 13 insertions, 3 deletions
diff --git a/src/mod_http_fileserver.erl b/src/mod_http_fileserver.erl
index c2144042e..4e3cfd08b 100644
--- a/src/mod_http_fileserver.erl
+++ b/src/mod_http_fileserver.erl
@@ -59,8 +59,13 @@
-define(HTTP_ERR_FILE_NOT_FOUND,
{-1, 404, [], <<"Not found">>}).
+-define(REQUEST_AUTH_HEADERS,
+ [{<<"WWW-Authenticate">>, <<"Basic realm=\"ejabberd\"">>}]).
+
-define(HTTP_ERR_FORBIDDEN,
{-1, 403, [], <<"Forbidden">>}).
+-define(HTTP_ERR_REQUEST_AUTH,
+ {-1, 401, ?REQUEST_AUTH_HEADERS, <<"Unauthorized">>}).
-define(DEFAULT_CONTENT_TYPE,
<<"application/octet-stream">>).
@@ -317,12 +322,17 @@ serve(LocalPath, Auth, DocRoot, DirectoryIndices, CustomHeaders, DefaultContentT
false
end,
case CanProceed of
+ false ->
+ ?HTTP_ERR_REQUEST_AUTH;
true ->
FileName = filename:join(filename:split(DocRoot) ++ LocalPath),
case file:read_file_info(FileName) of
- {error, enoent} -> ?HTTP_ERR_FILE_NOT_FOUND;
- {error, enotdir} -> ?HTTP_ERR_FILE_NOT_FOUND;
- {error, eacces} -> ?HTTP_ERR_FORBIDDEN;
+ {error, enoent} ->
+ ?HTTP_ERR_FILE_NOT_FOUND;
+ {error, enotdir} ->
+ ?HTTP_ERR_FILE_NOT_FOUND;
+ {error, eacces} ->
+ ?HTTP_ERR_FORBIDDEN;
{ok, #file_info{type = directory}} -> serve_index(FileName,
DirectoryIndices,
CustomHeaders,