diff options
Diffstat (limited to 'response.cpp')
-rw-r--r-- | response.cpp | 7 |
1 files changed, 6 insertions, 1 deletions
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<std::string, std::function<std::string(RequestContext&)>> 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); } } |