Commit 45f36f7f authored by Miguel Sacristan's avatar Miguel Sacristan

Added Macro "CUSTOM_HEADER" for very basic HTTP Headers

parent 9b2a7a5b
......@@ -552,6 +552,25 @@ private:
std::string ua_;
};
#define CUSTOM_HEADER(header_name) \
class header_name : public Pistache::Http::Header::Header { \
public: \
NAME(#header_name) \
\
header_name() = default; \
\
explicit header_name(const char* value) \
: value_{value} {} \
\
explicit header_name(const std::string& value) \
: value_(value) {} \
\
void write(std::ostream& os) const final { os << value_; }; \
\
private: \
std::string value_; \
}; \
class Raw {
public:
Raw();
......
/* mime.cc
Mathieu Stefani, 29 August 2015
Implementaton of MIME Type parsing
Implementation of MIME Type parsing
*/
#include <cstring>
......
......@@ -280,7 +280,7 @@ Pistache::Rest::SegmentTreeNode::findRoute(
} else { // current leaf requested, or empty final optional
if (!optional_.empty()) {
// in case of more than one optional at this point, as it is an
// ambuiguity, it is resolved by using the first optional
// ambiguity, it is resolved by using the first optional
auto optional = optional_.begin();
// std::string opt {optional->first.data(), optional->first.length()};
return optional->second->findRoute(path, params, splats);
......
......@@ -8,14 +8,7 @@
using namespace Pistache::Http;
class TestHeader : public Header::Header {
public:
NAME("TestHeader");
void write(std::ostream& os) const override {
os << "TestHeader";
}
};
CUSTOM_HEADER(TestHeader)
TEST(headers_test, accept) {
Header::Accept a1;
......@@ -336,6 +329,7 @@ TEST(headers_test, add_new_header_test)
ASSERT_FALSE(Header::Registry::instance().isRegistered(headerName));
Header::Registry::instance().registerHeader<TestHeader>();
ASSERT_TRUE(TestHeader::Name == "TestHeader");
ASSERT_TRUE(Header::Registry::instance().isRegistered(headerName));
const auto& headersList = Header::Registry::instance().headersList();
......
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