123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102 |
- /*
- * This file is part of the UCB release of Plan 9. It is subject to the license
- * terms in the LICENSE file found in the top-level directory of this
- * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No
- * part of the UCB release of Plan 9, including this file, may be copied,
- * modified, propagated, or distributed except according to the terms contained
- * in the LICENSE file.
- */
- #include <u.h>
- #include <libc.h>
- #include <bin.h>
- #include <httpd.h>
- typedef struct Error Error;
- struct Error
- {
- char *num;
- char *concise;
- char *verbose;
- };
- Error errormsg[] =
- {
- [HInternal] = {"500 Internal Error", "Internal Error",
- "This server could not process your request due to an internal error."},
- [HTempFail] = {"500 Internal Error", "Temporary Failure",
- "The object %s is currently inaccessible.<p>Please try again later."},
- [HUnimp] = {"501 Not implemented", "Command not implemented",
- "This server does not implement the %s command."},
- [HUnkVers] = {"501 Not Implemented", "Unknown http version",
- "This server does not know how to respond to http version %s."},
- [HBadCont] = {"501 Not Implemented", "Impossible format",
- "This server cannot produce %s in any of the formats your client accepts."},
- [HBadReq] = {"400 Bad Request", "Strange Request",
- "Your client sent a query that this server could not understand."},
- [HSyntax] = {"400 Bad Request", "Garbled Syntax",
- "Your client sent a query with incoherent syntax."},
- [HBadSearch] = {"400 Bad Request", "Inapplicable Search",
- "Your client sent a search that cannot be applied to %s."},
- [HNotFound] = {"404 Not Found", "Object not found",
- "The object %s does not exist on this server."},
- [HNoSearch] = {"403 Forbidden", "Search not supported",
- "The object %s does not support the search command."},
- [HNoData] = {"403 Forbidden", "No data supplied",
- "Search or forms data must be supplied to %s."},
- [HExpectFail] = {"403 Expectation Failed", "Expectation Failed",
- "This server does not support some of your request's expectations."},
- [HUnauth] = {"403 Forbidden", "Forbidden",
- "You are not allowed to see the object %s."},
- [HOK] = {"200 OK", "everything is fine"},
- };
- /*
- * write a failure message to the net and exit
- */
- int
- hfail(HConnect *c, int reason, ...)
- {
- Hio *hout;
- char makeup[HBufSize], err[ERRMAX];
- va_list arg;
- int n;
- rerrstr(err, sizeof err);
- hout = &c->hout;
- va_start(arg, reason);
- vseprint(makeup, makeup+HBufSize, errormsg[reason].verbose, arg);
- va_end(arg);
- /*
- * this additional information has proved useful when debugging
- * complex http configuration problems.
- */
- n = snprint(c->xferbuf, HBufSize, "<head><title>%s</title></head>\n"
- "<body><h1>%s</h1>\n%s<p>\n"
- "errstr: %s<br>\n"
- "uri host: %s<br>\n"
- "header host: %s<br>\nactual host: %s\n</body>\n",
- errormsg[reason].concise, errormsg[reason].concise, makeup,
- err,
- (c->req.urihost? c->req.urihost: ""),
- c->head.host, hmydomain);
- hprint(hout, "%s %s\r\n", hversion, errormsg[reason].num);
- hprint(hout, "Date: %D\r\n", time(nil));
- hprint(hout, "Server: Plan9\r\n");
- hprint(hout, "Content-Type: text/html\r\n");
- hprint(hout, "Content-Length: %d\r\n", n);
- if(c->head.closeit)
- hprint(hout, "Connection: close\r\n");
- else if(!http11(c))
- hprint(hout, "Connection: Keep-Alive\r\n");
- hprint(hout, "\r\n");
- if(c->req.meth == nil || strcmp(c->req.meth, "HEAD") != 0)
- hwrite(hout, c->xferbuf, n);
- if(c->replog)
- c->replog(c, "Reply: %s\nReason: %s\n", errormsg[reason].num, errormsg[reason].concise);
- return hflush(hout);
- }
|