~ubuntu-branches/debian/squeeze/erlang/squeeze

« back to all changes in this revision

Viewing changes to lib/inets/src/mod_head.erl

  • Committer: Bazaar Package Importer
  • Author(s): Erlang Packagers, Sergei Golovan
  • Date: 2006-12-03 17:07:44 UTC
  • mfrom: (2.1.11 feisty)
  • Revision ID: james.westby@ubuntu.com-20061203170744-rghjwupacqlzs6kv
Tags: 1:11.b.2-4
[ Sergei Golovan ]
Fixed erlang-base and erlang-base-hipe prerm scripts.

Show diffs side-by-side

added added

removed removed

Lines of Context:
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/.
6
 
%% 
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
10
 
%% under the License.
11
 
%% 
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.''
15
 
%% 
16
 
%%     $Id$
17
 
%%
18
 
-module(mod_head).
19
 
-export([do/1]).
20
 
 
21
 
-include("httpd.hrl").
22
 
 
23
 
%% do
24
 
 
25
 
do(Info) ->
26
 
    ?DEBUG("do -> entry",[]),
27
 
    case Info#mod.method of
28
 
        "HEAD" ->
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!
34
 
                _undefined ->
35
 
                    case httpd_util:key1search(Info#mod.data,response) of
36
 
                        %% No response has been generated!
37
 
                        undefined ->
38
 
                            do_head(Info);
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}
45
 
                    end
46
 
            end;
47
 
        %% Not a HEAD method!
48
 
        _ ->
49
 
            {proceed,Info#mod.data}
50
 
    end.
51
 
 
52
 
do_head(Info) -> 
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
59
 
        {ok,FileInfo} ->
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]};
64
 
        {error,Reason} ->
65
 
            {proceed,
66
 
             [{status,read_file_info_error(Reason,Info,Path)}|Info#mod.data]}
67
 
    end.
68
 
 
69
 
%% read_file_info_error - Handle file info read failure
70
 
%%
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,"").
84
 
 
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)}.