1 /* Deliver errors back to the user.
2 * - by Richard W.M. Jones <rich@annexia.org>
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Library General Public License for more details.
14 * You should have received a copy of the GNU Library General Public
15 * License along with this library; if not, write to the Free
16 * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18 * $Id: errors.c,v 1.5 2002/12/01 14:58:01 rich Exp $
25 #include <pthr_pseudothread.h>
26 #include <pthr_http.h>
27 #include <pthr_iolib.h>
29 #include "process_rq.h"
34 bad_request_error (process_rq p, const char *text)
36 http_response http_response;
38 const char *maintainer;
40 maintainer = cfg_get_string (p->host, p->alias,
41 "maintainer", "(no maintainer)"); /* XXX */
43 http_response = new_http_response (p->pool, p->http_request, p->io,
44 500, "Internal server error");
45 http_response_send_headers (http_response,
47 "Content-Type", "text/html",
51 close = http_response_end_headers (http_response);
53 if (http_request_is_HEAD (p->http_request)) return close;
57 "<html><head><title>Internal server error</title></head>" CRLF
58 "<body bgcolor=\"#ffffff\">" CRLF
59 "<h1>500 Internal server error</h1>" CRLF
60 "There was an error serving this request:" CRLF
65 "<address>%s</address>" CRLF
66 "</body></html>" CRLF,
69 /* It's always a good idea to force the connection to close after an
70 * error. This is particularly important with monolith applications
71 * after they have thrown an exception.
78 file_not_found_error (process_rq p)
80 http_response http_response;
82 const char *maintainer;
84 maintainer = cfg_get_string (p->host, p->alias,
85 "maintainer", "(no maintainer)");
87 http_response = new_http_response (p->pool, p->http_request, p->io,
88 404, "File or directory not found");
89 http_response_send_headers (http_response,
91 "Content-Type", "text/html",
95 close = http_response_end_headers (http_response);
97 if (http_request_is_HEAD (p->http_request)) return close;
100 "<html><head><title>File or directory not found</title></head>" CRLF
101 "<body bgcolor=\"#ffffff\">" CRLF
102 "<h1>404 File or directory not found</h1>" CRLF
103 "The file you requested was not found on this server." CRLF
105 "<address>%s</address>" CRLF
106 "</body></html>" CRLF,
113 moved_permanently (process_rq p, const char *location)
115 http_response http_response;
118 http_response = new_http_response (p->pool, p->http_request, p->io,
119 301, "Moved permanently");
120 http_response_send_headers (http_response,
121 /* Content length. */
122 "Content-Length", "0",
124 "Location", location,
125 /* End of headers. */
127 close = http_response_end_headers (http_response);
129 if (http_request_is_HEAD (p->http_request)) return close;