summaryrefslogtreecommitdiffhomepage
path: root/response.cpp
diff options
context:
space:
mode:
authorRoland Reichwein <mail@reichwein.it>2020-04-13 19:36:15 +0200
committerRoland Reichwein <mail@reichwein.it>2020-04-13 19:36:15 +0200
commit6b91026eddfa739b6637b18285041063e0fd0348 (patch)
tree728375b29278bd1a1e71464d7818f69c38ecea1f /response.cpp
parent5b3022c4a0e81ff23ce4ebc2ec7b03e32f7a719e (diff)
Fix webbox (WIP)
Diffstat (limited to 'response.cpp')
-rw-r--r--response.cpp13
1 files changed, 11 insertions, 2 deletions
diff --git a/response.cpp b/response.cpp
index a70a694..5c68d51 100644
--- a/response.cpp
+++ b/response.cpp
@@ -42,7 +42,10 @@ public:
std::string GetRelativePath() const { // can throw std::runtime_error
if (!boost::starts_with(m_target, m_path.requested))
throw std::runtime_error("Mismatch of target ("s + m_target + ") and plugin path(" + m_path.requested + ")"s);
- return m_target.substr(m_path.requested.size());
+ if (m_target.size() > m_path.requested.size() && m_target[m_path.requested.size()] == '/')
+ return m_target.substr(m_path.requested.size() + 1);
+ else
+ return m_target.substr(m_path.requested.size());
}
std::string GetPluginParam(const std::string& key) const {return m_path.params.at(key);} // can throw std::out_of_range
@@ -52,11 +55,13 @@ public:
request_type& GetReq() const {return m_req;}
std::string GetTarget() const {return m_target;}
+
+ std::string GetHost() const {return m_host;}
};
std::string extend_index_html(std::string path)
{
- if (path.size() && path.back() == '/')
+ if (path.size() == 0 || path.back() == '/')
path.append("index.html");
return path;
}
@@ -83,6 +88,8 @@ std::unordered_map<std::string, std::function<std::string(RequestContext&)>> Get
{"content_type", [](RequestContext& req_ctx) { return std::string{req_ctx.GetReq()["content_type"]}; }}, // TODO: does this work?
{"method", [](RequestContext& req_ctx) { return std::string{req_ctx.GetReq().method_string()};}},
+
+ {"location", [](RequestContext& req_ctx) { return req_ctx.GetTarget(); }},
};
std::string GetRequestParam(const std::string& key, RequestContext& req_ctx)
@@ -129,6 +136,8 @@ void SetResponseHeader(const std::string& key, const std::string& value, respons
res.set(http::field::content_type, value);
} else if (key == "content_disposition") { // e.g. attachment; ...
res.set(http::field::content_disposition, value);
+ } else if (key == "location") { // e.g. 301 Moved Permanently: new Location
+ res.set(http::field::location, value);
} else
throw std::runtime_error("Unsupported response field: "s + key);
}