summaryrefslogtreecommitdiffhomepage
path: root/https.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'https.cpp')
-rw-r--r--https.cpp65
1 files changed, 9 insertions, 56 deletions
diff --git a/https.cpp b/https.cpp
index f312295..d410bb3 100644
--- a/https.cpp
+++ b/https.cpp
@@ -88,63 +88,16 @@ handle_request(
http::request<Body, http::basic_fields<Allocator>>&& req,
Send&& send)
{
- // Returns a bad request response
- auto const bad_request =
- [&req](beast::string_view why)
- {
- http::response<http::string_body> res{http::status::bad_request, req.version()};
- res.set(http::field::server, VersionString);
- res.set(http::field::content_type, "text/html");
- res.keep_alive(req.keep_alive());
- res.body() = std::string(why);
- res.prepare_payload();
- return res;
- };
-
- // Returns a not found response
- auto const not_found =
- [&req](beast::string_view target)
- {
- http::response<http::string_body> res{http::status::not_found, req.version()};
- res.set(http::field::server, VersionString);
- res.set(http::field::content_type, "text/html");
- res.keep_alive(req.keep_alive());
- res.body() = "The resource '" + std::string(target) + "' was not found.";
- res.prepare_payload();
- return res;
- };
-
- // Returns a server error response
- auto const server_error =
- [&req](beast::string_view what)
- {
- http::response<http::string_body> res{http::status::internal_server_error, req.version()};
- res.set(http::field::server, VersionString);
- res.set(http::field::content_type, "text/html");
- res.keep_alive(req.keep_alive());
- res.body() = "An error occurred: '" + std::string(what) + "'";
- res.prepare_payload();
- return res;
- };
-
- try {
- http::response<http::string_body> res{http::status::ok, req.version()};
- res.set(http::field::server, VersionString);
- res.set(http::field::content_type, mime_type(extend_index_html(std::string(req.target()))));
- res.keep_alive(req.keep_alive());
- std::string res_data = generate_response(req, res, server);
- if (req.method() != http::verb::head) {
- res.body() = res_data;
- res.content_length(res_data.size());
- }
- return send(std::move(res));
- } catch(const bad_request_exception& ex) {
- return send(bad_request(ex.what()));
- } catch(const not_found_exception& ex) {
- return send(not_found(ex.what()));
- } catch(const server_error_exception& ex) {
- return send(server_error(ex.what()));
+ http::response<http::string_body> res{http::status::ok, req.version()};
+ res.set(http::field::server, VersionString);
+ res.set(http::field::content_type, mime_type(extend_index_html(std::string(req.target()))));
+ res.keep_alive(req.keep_alive());
+ std::string res_data = generate_response(req, res, server);
+ if (req.method() != http::verb::head) {
+ res.body() = res_data;
+ res.prepare_payload();
}
+ return send(std::move(res));
}
//------------------------------------------------------------------------------