Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 104 lines (83 sloc) 2.356 kb
1dca7ab @klacke 404 module added
authored
1 %%%----------------------------------------------------------------------
c1cea99 @faal Changed the way authentication is done, added support for multiple au…
faal authored
2 %%% File : yaws_outmod.erl
1dca7ab @klacke 404 module added
authored
3 %%% Author : Claes Wikstrom <klacke@hyber.org>
455578a @vinoski major trailing whitespace cleanup
vinoski authored
4 %%% Purpose :
1dca7ab @klacke 404 module added
authored
5 %%% Created : 4 Nov 2002 by Claes Wikstrom <klacke@hyber.org>
6 %%%----------------------------------------------------------------------
7
c1cea99 @faal Changed the way authentication is done, added support for multiple au…
faal authored
8 -module(yaws_outmod).
1dca7ab @klacke 404 module added
authored
9 -author('klacke@hyber.org').
10
7cb9a46 @klacke customized crash messages
authored
11
1dca7ab @klacke 404 module added
authored
12 -include("../include/yaws.hrl").
13 -include("../include/yaws_api.hrl").
14
d5676b2 @klacke Auth enhancements by Anders Dahlin,
authored
15 -export([out401/3,
16 out404/3,
0be3c7e @klacke untabified all of yaws
authored
17 out404/1,
5c3c546 @faal Yaws patch
faal authored
18 out/1,
0be3c7e @klacke untabified all of yaws
authored
19 crashmsg/3]).
7cb9a46 @klacke customized crash messages
authored
20
21
1dca7ab @klacke 404 module added
authored
22 %% The default error 404 error delivery module
281a3ca @klacke ""
authored
23 %% This function can be used to generate
24 %% a special page on 404's (it doesn't even have to be a 404)
1dca7ab @klacke 404 module added
authored
25
281a3ca @klacke ""
authored
26
ef3a52a @klacke Removed the atoms in parse_post and parse query, backwards incompatib…
authored
27
28
29 out404(Arg) ->
30 out404(Arg, get(gc), get(sc)).
281a3ca @klacke ""
authored
31 out404(Arg, GC, SC) ->
1dca7ab @klacke 404 module added
authored
32 Req = Arg#arg.req,
33 {abs_path, Path} = Req#http_request.path,
34 B = not_found_body(Path, GC, SC),
2135454 @klacke ""
authored
35 [{status, 404},
36 {header, {content_type, "text/html"}},
37 {header, {connection, "close"}},
38 {html, B}].
1dca7ab @klacke 404 module added
authored
39
40
41
c1cea99 @faal Changed the way authentication is done, added support for multiple au…
faal authored
42 %% The default error 401 error delivery module
43 %% This function can be used to generate
44 %% a special page on 401's (it doesn't even have to be a 401)
d5676b2 @klacke Auth enhancements by Anders Dahlin,
authored
45 out401(_Arg, _Auth, _Realm) ->
46 {ehtml,
47 [{html,[],
48 [
49 {body, [],
50 [{h1,[], "401 authentication needed"}
51 ]
52 }
53 ]
54 }
55 ]
56 }.
57
58 %% Deprecated, out401/3 will be used
5c3c546 @faal Yaws patch
faal authored
59 out(_Arg) ->
c1cea99 @faal Changed the way authentication is done, added support for multiple au…
faal authored
60 {ehtml,
455578a @vinoski major trailing whitespace cleanup
vinoski authored
61 [{html,[],
c1cea99 @faal Changed the way authentication is done, added support for multiple au…
faal authored
62 [
63 {body, [],
64 [{h1,[], "401 authentication needed"}
65 ]
66 }
67 ]
68 }
69 ]
3c41877 @faal 1. Fixed so that the HTTP status is set to 401 explicitly in
faal authored
70 }.
c1cea99 @faal Changed the way authentication is done, added support for multiple au…
faal authored
71
49cbf48 @klacke nice cleanup patch from Rickard Bucker
authored
72 not_found_body(Path, _GC, _SC) ->
1dca7ab @klacke 404 module added
authored
73 L = ["<!DOCTYPE HTML PUBLIC \"-//IETF//DTD HTML 2.0//EN\">"
0be3c7e @klacke untabified all of yaws
authored
74 "<HTML><HEAD>"
75 "<TITLE>404 Not Found</TITLE>"
76 "</HEAD><BODY>"
77 "<H1>Not Found</H1>"
455578a @vinoski major trailing whitespace cleanup
vinoski authored
78 "The requested URL ",
79 yaws_api:htmlize(Path),
0be3c7e @klacke untabified all of yaws
authored
80 " was not found on this server.<P>"
81 "<HR>",
82 yaws:address(),
83 " </BODY></HTML>"
84 ],
1dca7ab @klacke 404 module added
authored
85 list_to_binary(L).
86
87
88
7cb9a46 @klacke customized crash messages
authored
89
455578a @vinoski major trailing whitespace cleanup
vinoski authored
90 %% possibility to customize crash messages,
7cb9a46 @klacke customized crash messages
authored
91
0be3c7e @klacke untabified all of yaws
authored
92 %% while developing
7cb9a46 @klacke customized crash messages
authored
93 %% it's extremely convenient to get the crash messages in the browser,
94 %% however not in production :-)
9abef82 @klacke Make crashmsg set status code 500
authored
95 %% This function can only return an {ehtml, EH} or an {html, HTML}
96 %% value, no status codes, no headers etc.
2135454 @klacke ""
authored
97 crashmsg(_Arg, _SC, L) ->
7cb9a46 @klacke customized crash messages
authored
98 {ehtml,
99 [{h2, [], "Internal error, yaws code crashed"},
100 {br},
101 {hr},
102 {pre, [], L},
103 {hr}]}.
Something went wrong with that request. Please try again.