1
%% ``The contents of this file are subject to the Erlang Public License,
2
%% Version 1.1, (the "License"); you may not use this file except in
3
%% compliance with the License. You should have received a copy of the
4
%% Erlang Public License along with this software. If not, it can be
5
%% retrieved via the world wide web at http://www.erlang.org/.
7
%% Software distributed under the License is distributed on an "AS IS"
8
%% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
9
%% the License for the specific language governing rights and limitations
12
%% The Initial Developer of the Original Code is Ericsson Utvecklings AB.
13
%% Portions created by Ericsson are Copyright 1999, Ericsson Utvecklings
14
%% AB. All Rights Reserved.''
21
-include("httpd.hrl").
26
?DEBUG("do -> entry",[]),
27
case Info#mod.method of
29
case httpd_util:key1search(Info#mod.data,status) of
30
%% A status code has been generated!
31
{StatusCode,PhraseArgs,Reason} ->
32
{proceed,Info#mod.data};
33
%% No status code has been generated!
35
case httpd_util:key1search(Info#mod.data,response) of
36
%% No response has been generated!
39
%% A response has been sent! Nothing to do about it!
40
{already_sent,StatusCode,Size} ->
41
{proceed,Info#mod.data};
42
%% A response has been generated!
43
{StatusCode,Response} ->
44
{proceed,Info#mod.data}
49
{proceed,Info#mod.data}
53
?DEBUG("do_head -> Request URI: ~p",[Info#mod.request_uri]),
54
Path = mod_alias:path(Info#mod.data,Info#mod.config_db,
55
Info#mod.request_uri),
56
Suffix = httpd_util:suffix(Path),
57
%% Does the file exists?
58
case file:read_file_info(Path) of
60
MimeType=httpd_util:lookup_mime_default(Info#mod.config_db,Suffix,"text/plain"),
61
Length=io_lib:write(FileInfo#file_info.size),
62
Head=[{content_type,MimeType},{content_length,Length},{code,200}],
63
{proceed,[{response,{response,Head,nobody}}|Info#mod.data]};
66
[{status,read_file_info_error(Reason,Info,Path)}|Info#mod.data]}
69
%% read_file_info_error - Handle file info read failure
71
read_file_info_error(eacces,Info,Path) ->
72
read_file_info_error(403,Info,Path,"");
73
read_file_info_error(enoent,Info,Path) ->
74
read_file_info_error(404,Info,Path,"");
75
read_file_info_error(enotdir,Info,Path) ->
76
read_file_info_error(404,Info,Path,
77
": A component of the file name is not a directory");
78
read_file_info_error(emfile,_Info,Path) ->
79
read_file_info_error(500,none,Path,": To many open files");
80
read_file_info_error({enfile,_},_Info,Path) ->
81
read_file_info_error(500,none,Path,": File table overflow");
82
read_file_info_error(_Reason,_Info,Path) ->
83
read_file_info_error(500,none,Path,"").
85
read_file_info_error(StatusCode,none,Path,Reason) ->
86
{StatusCode,none,?NICE("Can't access "++Path++Reason)};
87
read_file_info_error(StatusCode,Info,Path,Reason) ->
88
{StatusCode,Info#mod.request_uri,
89
?NICE("Can't access "++Path++Reason)}.