mirror of
https://github.com/KingDuckZ/kamokan.git
synced 2025-10-02 15:00:02 +00:00
Redirects always use 3xx status codes.
This commit is contained in:
parent
c6955cd8b9
commit
810c321515
5 changed files with 12 additions and 14 deletions
|
@ -3,7 +3,6 @@
|
||||||
{{> topbar}}
|
{{> topbar}}
|
||||||
<div id="content" class="error">
|
<div id="content" class="error">
|
||||||
|
|
||||||
{{error_code}}
|
|
||||||
{{error_message}}
|
{{error_message}}
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -38,7 +38,6 @@ namespace tawashi {
|
||||||
|
|
||||||
void ErrorResponse::on_mustache_prepare (mstch::map& parContext) {
|
void ErrorResponse::on_mustache_prepare (mstch::map& parContext) {
|
||||||
auto get = cgi_env().query_string_split();
|
auto get = cgi_env().query_string_split();
|
||||||
auto err_code = boost::lexical_cast<int>(get["code"]);
|
|
||||||
const int reason_int = boost::lexical_cast<int>(get["reason"]);
|
const int reason_int = boost::lexical_cast<int>(get["reason"]);
|
||||||
ErrorReasons reason_code(ErrorReasons::UnkownReason);
|
ErrorReasons reason_code(ErrorReasons::UnkownReason);
|
||||||
if (reason_int >= 0 and reason_int < ErrorReasons::_size())
|
if (reason_int >= 0 and reason_int < ErrorReasons::_size())
|
||||||
|
@ -62,7 +61,6 @@ namespace tawashi {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
parContext["error_message"] = std::string(err_descs[reason_code], lengths[reason_code]);
|
parContext["error_message"] = std::string(err_descs[reason_code], lengths[reason_code]);
|
||||||
parContext["error_code"] = std::to_string(err_code);
|
|
||||||
parContext["error_id"] = std::to_string(reason_code);
|
parContext["error_id"] = std::to_string(reason_code);
|
||||||
}
|
}
|
||||||
} //namespace tawashi
|
} //namespace tawashi
|
||||||
|
|
|
@ -240,13 +240,14 @@ namespace tawashi {
|
||||||
return HttpHeader(HttpHeader::Location, parCode, oss.str());
|
return HttpHeader(HttpHeader::Location, parCode, oss.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
HttpHeader Response::make_error_redirect (HttpStatusCodes parCode, ErrorReasons parReason) {
|
HttpHeader Response::make_error_redirect (ErrorReasons parReason) {
|
||||||
auto statuslog = spdlog::get("statuslog");
|
auto statuslog = spdlog::get("statuslog");
|
||||||
assert(statuslog);
|
assert(statuslog);
|
||||||
statuslog->info("Redirecting to error page, code={} reason={}", parCode, parReason);
|
const HttpStatusCodes redir_code = HttpStatusCodes::Code302_Found;
|
||||||
|
statuslog->info("Redirecting to error page, code={} reason={}", redir_code, parReason);
|
||||||
|
|
||||||
std::ostringstream oss;
|
std::ostringstream oss;
|
||||||
oss << "error.cgi?code=" << parCode._to_integral() << "&reason=" << parReason._to_integral();
|
oss << "error.cgi?reason=" << parReason._to_integral();
|
||||||
return make_redirect(parCode, oss.str());
|
return make_redirect(redir_code, oss.str());
|
||||||
}
|
}
|
||||||
} //namespace tawashi
|
} //namespace tawashi
|
||||||
|
|
|
@ -58,7 +58,7 @@ namespace tawashi {
|
||||||
const SettingsBag& settings() const;
|
const SettingsBag& settings() const;
|
||||||
virtual std::string load_mustache() const;
|
virtual std::string load_mustache() const;
|
||||||
HttpHeader make_redirect (HttpStatusCodes parCode, const std::string& parLocation);
|
HttpHeader make_redirect (HttpStatusCodes parCode, const std::string& parLocation);
|
||||||
HttpHeader make_error_redirect (HttpStatusCodes parCode, ErrorReasons parReason);
|
HttpHeader make_error_redirect (ErrorReasons parReason);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
virtual HttpHeader on_process();
|
virtual HttpHeader on_process();
|
||||||
|
|
|
@ -123,7 +123,7 @@ namespace tawashi {
|
||||||
}
|
}
|
||||||
catch (const TawashiException& e) {
|
catch (const TawashiException& e) {
|
||||||
statuslog->error(e.what());
|
statuslog->error(e.what());
|
||||||
return make_error_redirect(HttpStatusCodes::Code500_InternalServerError, e.reason());
|
return make_error_redirect(e.reason());
|
||||||
}
|
}
|
||||||
|
|
||||||
lang = get_value_from_post_log_failure(post, make_string_ref(g_language_key));
|
lang = get_value_from_post_log_failure(post, make_string_ref(g_language_key));
|
||||||
|
@ -132,14 +132,14 @@ namespace tawashi {
|
||||||
const SettingsBag& settings = this->settings();
|
const SettingsBag& settings = this->settings();
|
||||||
const auto max_sz = settings.as<uint32_t>("max_pastie_size");
|
const auto max_sz = settings.as<uint32_t>("max_pastie_size");
|
||||||
if (pastie.size() < settings.as<uint32_t>("min_pastie_size")) {
|
if (pastie.size() < settings.as<uint32_t>("min_pastie_size")) {
|
||||||
return make_error_redirect(HttpStatusCodes::Code431_RequestHeaderFieldsTooLarge, ErrorReasons::PostLengthNotInRange);
|
return make_error_redirect(ErrorReasons::PostLengthNotInRange);
|
||||||
}
|
}
|
||||||
if (max_sz and pastie.size() > max_sz) {
|
if (max_sz and pastie.size() > max_sz) {
|
||||||
if (settings.as<bool>("truncate_long_pasties")) {
|
if (settings.as<bool>("truncate_long_pasties")) {
|
||||||
pastie = pastie.substr(0, max_sz);
|
pastie = pastie.substr(0, max_sz);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
return make_error_redirect(HttpStatusCodes::Code431_RequestHeaderFieldsTooLarge, ErrorReasons::PostLengthNotInRange);
|
return make_error_redirect(ErrorReasons::PostLengthNotInRange);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -170,13 +170,13 @@ namespace tawashi {
|
||||||
) -> StringOrHeader {
|
) -> StringOrHeader {
|
||||||
auto& redis = this->redis();
|
auto& redis = this->redis();
|
||||||
if (not redis.is_connected()) {
|
if (not redis.is_connected()) {
|
||||||
return std::make_pair(boost::optional<std::string>(), make_error_redirect(HttpStatusCodes::Code503_ServiceUnavailable, ErrorReasons::RedisDisconnected));
|
return std::make_pair(boost::optional<std::string>(), make_error_redirect(ErrorReasons::RedisDisconnected));
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string ip_hash = hashed_ip(cgi_env().remote_addr());
|
std::string ip_hash = hashed_ip(cgi_env().remote_addr());
|
||||||
if (redis.get(ip_hash)) {
|
if (redis.get(ip_hash)) {
|
||||||
//please wait and submit again
|
//please wait and submit again
|
||||||
return std::make_pair(boost::optional<std::string>(), make_error_redirect(HttpStatusCodes::Code429_TooManyRequests, ErrorReasons::UserFlooding));
|
return std::make_pair(boost::optional<std::string>(), make_error_redirect(ErrorReasons::UserFlooding));
|
||||||
}
|
}
|
||||||
|
|
||||||
const auto next_id = redis.incr("paste_counter");
|
const auto next_id = redis.incr("paste_counter");
|
||||||
|
@ -193,6 +193,6 @@ namespace tawashi {
|
||||||
return std::make_pair(boost::make_optional(token), HttpHeader());
|
return std::make_pair(boost::make_optional(token), HttpHeader());
|
||||||
}
|
}
|
||||||
|
|
||||||
return std::make_pair(boost::optional<std::string>(), make_error_redirect(HttpStatusCodes::Code500_InternalServerError, ErrorReasons::PastieNotSaved));
|
return std::make_pair(boost::optional<std::string>(), make_error_redirect(ErrorReasons::PastieNotSaved));
|
||||||
}
|
}
|
||||||
} //namespace tawashi
|
} //namespace tawashi
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue