diff options
author | Roland Reichwein <mail@reichwein.it> | 2020-04-12 22:20:33 +0200 |
---|---|---|
committer | Roland Reichwein <mail@reichwein.it> | 2020-04-12 22:20:33 +0200 |
commit | 4732dc63657f4c6fc342f7674f7dc7c666b293dc (patch) | |
tree | da91a5dbbd62982284435d252dd89ac963952ee9 /response.cpp | |
parent | 3f778eecc705990598f1033e6245522f42e2fcb5 (diff) |
webbox (WIP)
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); } } |