/*
- * $Id: errorpage.cc,v 1.169 2002/04/01 06:02:15 wessels Exp $
+ * $Id: errorpage.cc,v 1.170 2002/04/02 11:38:03 hno Exp $
*
* DEBUG: section 4 Error Generation
* AUTHOR: Duane Wessels
"<hr noshade size=1>\n"
"Generated %T by %h (%s)\n"
"</BODY></HTML>\n"
+ },
+ {
+ TCP_RESET,
+ "reset"
}
};
/* dynamic */
ErrorDynamicPageInfo *info = ErrorDynamicPages.items[i - ERR_MAX];
assert(info && info->id == i && info->page_name);
- error_text[i] = errorLoadText(info->page_name);
+ if (strchr(info->page_name, ':') == NULL) {
+ /* Not on redirected errors... */
+ error_text[i] = errorLoadText(info->page_name);
+ }
}
- assert(error_text[i]);
}
}
xfree(info);
}
+static int
+errorPageId(const char *page_name)
+{
+ int i;
+ for (i = 0; i < ERR_MAX; i++) {
+ if (strcmp(err_type_str[i], page_name) == 0)
+ return i;
+ }
+ for (i = 0; i < ErrorDynamicPages.count; i++) {
+ if (strcmp(((ErrorDynamicPageInfo *) ErrorDynamicPages.items[i - ERR_MAX])->page_name, page_name) == 0)
+ return i + ERR_MAX;
+ }
+ return ERR_NONE;
+}
+
int
errorReservePageId(const char *page_name)
{
- ErrorDynamicPageInfo *info =
- errorDynamicPageInfoCreate(ERR_MAX + ErrorDynamicPages.count, page_name);
- stackPush(&ErrorDynamicPages, info);
- return info->id;
+ ErrorDynamicPageInfo *info;
+ int id = errorPageId(page_name);
+ if (id == ERR_NONE) {
+ info = errorDynamicPageInfoCreate(ERR_MAX + ErrorDynamicPages.count, page_name);
+ stackPush(&ErrorDynamicPages, info);
+ id = info->id;
+ }
+ return id;
}
static const char *
errorStateFree(err);
return;
}
- if (0 == strncmp(error_text[err->page_id], "reset", 5)) {
+ if (err->page_id == TCP_RESET) {
if (err->request) {
- debug(0, 0) ("RSTing this reply\n");
+ debug(4, 2) ("RSTing this reply\n");
err->request->flags.reset_tcp = 1;
}
}
* t - local time x
* T - UTC x
* U - URL without password x
- * u - URL without password, %2f added to path x
+ * u - URL with password x
* w - cachemgr email address x
* z - dns server error message x
*/
case 'U':
p = r ? urlCanonicalClean(r) : err->url ? err->url : "[no URL]";
break;
+ case 'u':
+ p = r ? urlCanonical(r) : err->url ? err->url : "[no URL]";
+ break;
case 'w':
if (Config.adminEmail)
memBufPrintf(&mb, "%s", Config.adminEmail);
errorBuildReply(ErrorState * err)
{
HttpReply *rep = httpReplyCreate();
- MemBuf content = errorBuildContent(err);
+ const char *name = errorPageName(err->page_id);
http_version_t version;
/* no LMT for error pages; error pages expire immediately */
httpBuildVersion(&version, 1, 0);
- httpReplySetHeaders(rep, version, err->http_status, NULL, "text/html", content.size, 0, squid_curtime);
- /*
- * include some information for downstream caches. Implicit
- * replaceable content. This isn't quite sufficient. xerrno is not
- * necessarily meaningful to another system, so we really should
- * expand it. Additionally, we should identify ourselves. Someone
- * might want to know. Someone _will_ want to know OTOH, the first
- * X-CACHE-MISS entry should tell us who.
- */
- httpHeaderPutStrf(&rep->header, HDR_X_SQUID_ERROR, "%s %d",
- errorPageName(err->page_id), err->xerrno);
- httpBodySet(&rep->body, &content);
- /* do not memBufClean() the content, it was absorbed by httpBody */
+ if (strchr(name, ':')) {
+ /* Redirection */
+ char *quoted_url = rfc1738_escape_part(errorConvert('u', err));
+ httpReplySetHeaders(rep, version, HTTP_MOVED_TEMPORARILY, NULL, "text/html", 0, 0, squid_curtime);
+ httpHeaderPutStrf(&rep->header, HDR_LOCATION, name, quoted_url);
+ httpHeaderPutStrf(&rep->header, HDR_X_SQUID_ERROR, "%d %s\n", err->http_status, "Access Denied");
+ } else {
+ MemBuf content = errorBuildContent(err);
+ httpReplySetHeaders(rep, version, err->http_status, NULL, "text/html", content.size, 0, squid_curtime);
+ /*
+ * include some information for downstream caches. Implicit
+ * replaceable content. This isn't quite sufficient. xerrno is not
+ * necessarily meaningful to another system, so we really should
+ * expand it. Additionally, we should identify ourselves. Someone
+ * might want to know. Someone _will_ want to know OTOH, the first
+ * X-CACHE-MISS entry should tell us who.
+ */
+ httpHeaderPutStrf(&rep->header, HDR_X_SQUID_ERROR, "%s %d",
+ name, err->xerrno);
+ httpBodySet(&rep->body, &content);
+ /* do not memBufClean() the content, it was absorbed by httpBody */
+ }
return rep;
}