From 4732dc63657f4c6fc342f7674f7dc7c666b293dc Mon Sep 17 00:00:00 2001 From: Roland Reichwein Date: Sun, 12 Apr 2020 22:20:33 +0200 Subject: webbox (WIP) --- response.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'response.cpp') diff --git a/response.cpp b/response.cpp index 1ee8932..ffd72b6 100644 --- a/response.cpp +++ b/response.cpp @@ -78,6 +78,8 @@ std::unordered_map> Get {"body", [](RequestContext& req_ctx) { return req_ctx.GetReq().body(); }}, + {"content_length", [](RequestContext& req_ctx) { return std::to_string(req_ctx.GetReq().body().size()); }}, + {"method", [](RequestContext& req_ctx) { return std::string{req_ctx.GetReq().method_string()};}}, }; @@ -100,10 +102,11 @@ std::string GetRequestParam(const std::string& key, RequestContext& req_ctx) } // third, look up req parameters + // contains: host { try { return std::string{req_ctx.GetReq()[key]}; - } catch(...){ + } catch(...) { // not found } } @@ -202,6 +205,8 @@ response_type generate_response(request_type& req, Server& server) return res; } catch(const std::out_of_range& ex) { return HttpStatus("400", "Bad request: Host "s + std::string{req["host"]} + ":"s + std::string{req.target()} + " unknown"s, res); + } catch(const std::exception& ex) { + return HttpStatus("400", "Bad request: "s + std::string{ex.what()}, res); } } -- cgit v1.2.3