summaryrefslogtreecommitdiff
path: root/usr.sbin/relayd/log.c
diff options
context:
space:
mode:
authorReyk Floeter <reyk@cvs.openbsd.org>2007-11-20 15:54:56 +0000
committerReyk Floeter <reyk@cvs.openbsd.org>2007-11-20 15:54:56 +0000
commite6c7ec852fff7782025440ba3dc423ef88e77468 (patch)
treeded00acf8d5fff247ba0242a56098a6f229155c4 /usr.sbin/relayd/log.c
parent06cda98f2ac65d76367d70562e5e25990af9200b (diff)
it may be desirable to send a HTTP error page with error code and a
meaningful message if a HTTP/HTTPS relay closes the connection for some reason. for example, a "403 Forbidden" if the request was rejected by a filter. this will be enabled with the "return error" option and is disabled by default, the standard behaviour is to silently drop the connection; the browser may display an empty page in this case. the look+feel of the HTTP error page can be customized with a CSS style sheet, but we do not intend to allow customization of the error page contents (hoststated is not a webserver!). ok pyr@
Diffstat (limited to 'usr.sbin/relayd/log.c')
-rw-r--r--usr.sbin/relayd/log.c58
1 files changed, 57 insertions, 1 deletions
diff --git a/usr.sbin/relayd/log.c b/usr.sbin/relayd/log.c
index 44724696450..2f2e37ce781 100644
--- a/usr.sbin/relayd/log.c
+++ b/usr.sbin/relayd/log.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: log.c,v 1.8 2007/11/04 22:09:02 reyk Exp $ */
+/* $OpenBSD: log.c,v 1.9 2007/11/20 15:54:55 reyk Exp $ */
/*
* Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org>
@@ -246,3 +246,59 @@ print_time(struct timeval *a, struct timeval *b, char *buf, size_t len)
snprintf(buf, len, "%.2lu:%.2lu:%.2lu", h, min, sec);
return (buf);
}
+
+const char *
+print_httperror(u_int code)
+{
+ u_int i;
+ struct {
+ u_int ht_code;
+ const char *ht_err;
+ } httperr[] = {
+ { 100, "Continue" },
+ { 101, "Switching Protocols" },
+ { 200, "OK" },
+ { 201, "Created" },
+ { 202, "Accepted" },
+ { 203, "Non-Authorative Information" },
+ { 204, "No Content" },
+ { 205, "Reset Content" },
+ { 206, "Partial Content" },
+ { 300, "Multiple Choices" },
+ { 301, "Moved Permanently" },
+ { 302, "Moved Temporarily" },
+ { 303, "See Other" },
+ { 304, "Not Modified" },
+ { 307, "Temporary Redirect" },
+ { 400, "Bad Request" },
+ { 401, "Unauthorized" },
+ { 402, "Payment Required" },
+ { 403, "Forbidden" },
+ { 404, "Not Found" },
+ { 405, "Method Not Allowed" },
+ { 406, "Not Acceptable" },
+ { 407, "Proxy Authentication Required" },
+ { 408, "Request Timeout" },
+ { 409, "Conflict" },
+ { 410, "Gone" },
+ { 411, "Length Required" },
+ { 412, "Precondition Failed" },
+ { 413, "Request Entity Too Large" },
+ { 414, "Request-URL Too Long" },
+ { 415, "Unsupported Media Type" },
+ { 416, "Requested Range Not Satisfiable" },
+ { 417, "Expectation Failed" },
+ { 500, "Internal Server Error" },
+ { 501, "Not Implemented" },
+ { 502, "Bad Gateway" },
+ { 503, "Service Unavailable" },
+ { 504, "Gateway Timeout" },
+ { 505, "HTTP Version Not Supported" },
+ { 0 }
+ };
+
+ for (i = 0; httperr[i].ht_code != 0; i++)
+ if (httperr[i].ht_code == code)
+ return (httperr[i].ht_err);
+ return ("Unknown Error");
+}