1
0
Fork 0
mirror of https://github.com/KingDuckZ/kamokan.git synced 2024-11-27 00:43:47 +00:00

Redirects always use 3xx status codes.

This commit is contained in:
King_DuckZ 2017-05-18 22:35:31 +01:00
parent c6955cd8b9
commit 810c321515
5 changed files with 12 additions and 14 deletions

View file

@ -3,7 +3,6 @@
{{> topbar}}
<div id="content" class="error">
{{error_code}}
{{error_message}}
</div>

View file

@ -38,7 +38,6 @@ namespace tawashi {
void ErrorResponse::on_mustache_prepare (mstch::map& parContext) {
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"]);
ErrorReasons reason_code(ErrorReasons::UnkownReason);
if (reason_int >= 0 and reason_int < ErrorReasons::_size())
@ -62,7 +61,6 @@ namespace tawashi {
#endif
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);
}
} //namespace tawashi

View file

@ -240,13 +240,14 @@ namespace tawashi {
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");
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;
oss << "error.cgi?code=" << parCode._to_integral() << "&reason=" << parReason._to_integral();
return make_redirect(parCode, oss.str());
oss << "error.cgi?reason=" << parReason._to_integral();
return make_redirect(redir_code, oss.str());
}
} //namespace tawashi

View file

@ -58,7 +58,7 @@ namespace tawashi {
const SettingsBag& settings() const;
virtual std::string load_mustache() const;
HttpHeader make_redirect (HttpStatusCodes parCode, const std::string& parLocation);
HttpHeader make_error_redirect (HttpStatusCodes parCode, ErrorReasons parReason);
HttpHeader make_error_redirect (ErrorReasons parReason);
private:
virtual HttpHeader on_process();

View file

@ -123,7 +123,7 @@ namespace tawashi {
}
catch (const TawashiException& e) {
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));
@ -132,14 +132,14 @@ namespace tawashi {
const SettingsBag& settings = this->settings();
const auto max_sz = settings.as<uint32_t>("max_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 (settings.as<bool>("truncate_long_pasties")) {
pastie = pastie.substr(0, max_sz);
}
else {
return make_error_redirect(HttpStatusCodes::Code431_RequestHeaderFieldsTooLarge, ErrorReasons::PostLengthNotInRange);
return make_error_redirect(ErrorReasons::PostLengthNotInRange);
}
}
@ -170,13 +170,13 @@ namespace tawashi {
) -> StringOrHeader {
auto& redis = this->redis();
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());
if (redis.get(ip_hash)) {
//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");
@ -193,6 +193,6 @@ namespace tawashi {
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