2009-01-26 19:21:29 +00:00
|
|
|
// vim:noexpandtab:syntax=lpc
|
2009-01-26 20:12:53 +00:00
|
|
|
// $Id: header.i,v 1.10 2008/08/05 12:21:33 lynx Exp $
|
2009-01-26 19:21:29 +00:00
|
|
|
|
|
|
|
#include <ht/http.h>
|
|
|
|
|
|
|
|
volatile int headerDone = 0;
|
|
|
|
|
|
|
|
http_ok(string prot, string type, string extra) {
|
2009-01-26 20:12:53 +00:00
|
|
|
string out;
|
2009-01-26 19:21:29 +00:00
|
|
|
|
|
|
|
// yes, this is compatible to pre-HTTP/1.0 browsers. sick, i know.
|
|
|
|
if (!prot || headerDone++) return;
|
|
|
|
|
2009-01-26 20:12:53 +00:00
|
|
|
out = type || extra ? htheaders(type, extra) +"\n"
|
2009-01-26 19:21:29 +00:00
|
|
|
: "Content-type: " DEFAULT_CONTENT_TYPE "\n\n";
|
2009-01-26 20:12:53 +00:00
|
|
|
emit(out = HTTP_SVERS " 200 Sure\n"+ out);
|
2010-02-22 07:33:32 +00:00
|
|
|
P3(("http_ok: out: %O\s", out))
|
2009-01-26 19:21:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
varargs http_error(string prot, int code, string comment, string html) {
|
|
|
|
string out;
|
|
|
|
|
2009-01-26 20:12:53 +00:00
|
|
|
// apparently there isn't a single app that calls this with "html"
|
|
|
|
P2(("hterror(%O,%O,%O,%O) in %O\n", prot,code,comment,html, ME))
|
2009-03-07 09:30:44 +00:00
|
|
|
#if defined(T)
|
2009-01-26 20:12:53 +00:00
|
|
|
// use the textdb if available
|
2020-10-23 11:22:39 +00:00
|
|
|
out = psyctext( T("_PAGES_error", "<title>Error [_code]</title><body><h1 id='code'>[_code]</h1><div id='comment'>[_comment]</div>"),
|
2009-01-26 20:12:53 +00:00
|
|
|
([ "_comment": comment, "_code": code ]) );
|
|
|
|
#else
|
|
|
|
// use some hardcoded defaults
|
2020-10-23 11:22:39 +00:00
|
|
|
out = "<body text='white' bgcolor='black' link='green' vlink='green'>\n";
|
2009-01-26 19:21:29 +00:00
|
|
|
if (html) out = sprintf("<title>%s</title>\n%s%s", comment, out, html);
|
|
|
|
else out = sprintf("\
|
2020-10-23 11:22:39 +00:00
|
|
|
<title>Error %d</title>\n\
|
2009-01-26 19:21:29 +00:00
|
|
|
%s\n\
|
2020-10-23 11:22:39 +00:00
|
|
|
<table width=\"100%%\" height=\"90%%\"><tr><th><h1><br/>\n\n\
|
2009-01-26 19:21:29 +00:00
|
|
|
%s\n\n\
|
|
|
|
</h1></th></tr></table>\n\
|
|
|
|
",
|
|
|
|
code, out, comment
|
|
|
|
);
|
|
|
|
// <a href=\"mailto:%s?subject=%s\">%s</a>\n
|
|
|
|
//, WEBMASTER_EMAIL, comment, WEBMASTER_EMAIL
|
2009-01-26 20:12:53 +00:00
|
|
|
#endif
|
2009-01-26 19:21:29 +00:00
|
|
|
// yes, this is compatible to pre-HTTP/1.0 browsers. sick, i know.
|
|
|
|
if (!headerDone++ && prot) {
|
|
|
|
// I used to output the comment, but Id have to cut out the
|
|
|
|
// newline from the db
|
2009-01-26 20:12:53 +00:00
|
|
|
emit(out = sprintf(HTTP_SVERS " 200 Actually %03d but MSIE steals my error page\n%s\n%s", code, htheaders(), out));
|
|
|
|
P3((out))
|
2009-01-26 19:21:29 +00:00
|
|
|
} else emit(out);
|
|
|
|
}
|