/*
- * Copyright (C) 1996-2022 The Squid Software Foundation and contributors
+ * Copyright (C) 1996-2023 The Squid Software Foundation and contributors
*
* Squid software is distributed under GPLv2+ license and includes
* contributions from numerous individuals and organizations.
#include "ssl/ErrorDetailManager.h"
#endif
+#include <array>
+
/**
\defgroup ErrorPageInternal Error Page Internals
\ingroup ErrorPageAPI
/* local constant and vars */
-/**
- \ingroup ErrorPageInternal
- *
- \note hard coded error messages are not appended with %S
- * automagically to give you more control on the format
- */
-static const struct {
- int type; /* and page_id */
- const char *text;
-}
-
-error_hard_text[] = {
+/// an error page (or a part of an error page) with hard-coded template text
+class HardCodedError {
+public:
+ err_type type; ///< identifies the error (or a special error template part)
+ const char *text; ///< a string literal containing the error template
+};
+/// error messages that cannot be configured/customized externally
+static const std::array<HardCodedError, 7> HardCodedErrors = {
{
- ERR_SQUID_SIGNATURE,
- "\n<br>\n"
- "<hr>\n"
- "<div id=\"footer\">\n"
- "Generated %T by %h (%s)\n"
- "</div>\n"
- "</body></html>\n"
- },
- {
- TCP_RESET,
- "reset"
- },
- {
- ERR_CLIENT_GONE,
- "unexpected client disconnect"
- },
- {
- ERR_SECURE_ACCEPT_FAIL,
- "secure accept fail"
- },
- {
- ERR_REQUEST_START_TIMEOUT,
- "request start timedout"
- },
- {
- MGR_INDEX,
- "mgr_index"
+ {
+ ERR_SQUID_SIGNATURE,
+ "\n<br>\n"
+ "<hr>\n"
+ "<div id=\"footer\">\n"
+ "Generated %T by %h (%s)\n"
+ "</div>\n"
+ "</body></html>\n"
+ },
+ {
+ TCP_RESET,
+ "reset"
+ },
+ {
+ ERR_CLIENT_GONE,
+ "unexpected client disconnect"
+ },
+ {
+ ERR_SECURE_ACCEPT_FAIL,
+ "secure accept fail"
+ },
+ {
+ ERR_REQUEST_START_TIMEOUT,
+ "request start timedout"
+ },
+ {
+ ERR_REQUEST_PARSE_TIMEOUT,
+ "request parse timedout"
+ },
+ {
+ ERR_RELAY_REMOTE,
+ "relay server response"
+ }
}
};
/* local prototypes */
-/// \ingroup ErrorPageInternal
-static const int error_hard_text_count = sizeof(error_hard_text) / sizeof(*error_hard_text);
-
/// \ingroup ErrorPageInternal
static char **error_text = nullptr;
const char *text() { return template_.c_str(); }
protected:
- virtual void setDefault() override {
+ void setDefault() override {
template_ = "Internal Error: Missing Template ";
template_.append(templateName.termedBuf());
}
static const char *
errorFindHardText(err_type type)
{
- int i;
-
- for (i = 0; i < error_hard_text_count; ++i)
- if (error_hard_text[i].type == type)
- return error_hard_text[i].text;
-
+ for (const auto &m: HardCodedErrors) {
+ if (m.type == type)
+ return m.text;
+ }
return nullptr;
}
case 'O':
if (!building_deny_info_url)
do_quote = 0;
- /* [[fallthrough]] */
+ [[fallthrough]];
case 'o':
p = request ? request->extacl_message.termedBuf() : external_acl_message;
if (!p && !building_deny_info_url)
*/
if (!Config.errorDirectory) {
/* We 'negotiated' this ONLY from the Accept-Language. */
- rep->header.delById(Http::HdrType::VARY);
- rep->header.putStr(Http::HdrType::VARY, "Accept-Language");
+ static const SBuf acceptLanguage("Accept-Language");
+ rep->header.updateOrAddStr(Http::HdrType::VARY, acceptLanguage);
}
/* add the Content-Language header according to RFC section 14.12 */