Commit a750622f authored by Mathieu Stefani's avatar Mathieu Stefani

Header::Collection: added an inplace construct function

parent efc830c1
...@@ -15,8 +15,8 @@ class MyHandler : public Net::Http::Handler { ...@@ -15,8 +15,8 @@ class MyHandler : public Net::Http::Handler {
using namespace Net::Http; using namespace Net::Http;
response.headers() response.headers()
.add(std::make_shared<Header::Server>("lys")) .add<Header::Server>("lys")
.add(std::make_shared<Header::ContentType>(MIME(Text, Plain))); .add<Header::ContentType>(MIME(Text, Plain));
auto w = response.beginWrite(Net::Http::Code::Ok); auto w = response.beginWrite(Net::Http::Code::Ok);
......
...@@ -53,6 +53,14 @@ public: ...@@ -53,6 +53,14 @@ public:
Collection& add(const std::shared_ptr<Header>& header); Collection& add(const std::shared_ptr<Header>& header);
Collection& addRaw(const Raw& raw); Collection& addRaw(const Raw& raw);
template<typename H, typename ...Args>
typename std::enable_if<
IsHeader<H>::value, Collection&
>::type
add(Args&& ...args) {
return add(std::make_shared<H>(std::forward<Args>(args)...));
}
std::shared_ptr<const Header> get(const std::string& name) const; std::shared_ptr<const Header> get(const std::string& name) const;
std::shared_ptr<Header> get(const std::string& name); std::shared_ptr<Header> get(const std::string& name);
Raw getRaw(const std::string& name) const; Raw getRaw(const std::string& name) const;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment