Commit 9ba1fce2 authored by Marcin Romanowski's avatar Marcin Romanowski

Adedd Authorization Header

parent acc1c838
......@@ -393,6 +393,27 @@ private:
uint64_t value_;
};
class Authorization : public Header {
public:
NAME("Authorization");
Authorization()
: value_("NONE")
{ }
explicit Authorization(std::string val)
: value_(val)
{ }
void parse(const std::string& data) override;
void write(std::ostream& os) const override;
std::string value() const { return value_; }
private:
std::string value_;
};
class ContentType : public Header {
public:
NAME("Content-Type")
......
......@@ -304,6 +304,19 @@ ContentLength::write(std::ostream& os) const {
os << value_;
}
void
Authorization::parse(const std::string& data) {
try {
value_ = data;
} catch (const std::invalid_argument& e) {
}
}
void
Authorization::write(std::ostream& os) const {
os << value_;
}
void
Date::parse(const std::string &str) {
fullDate_ = FullDate::fromString(str);
......
......@@ -27,6 +27,7 @@ RegisterHeader(ContentEncoding);
RegisterHeader(TransferEncoding);
RegisterHeader(ContentLength);
RegisterHeader(ContentType);
RegisterHeader(Authorization);
RegisterHeader(Date);
RegisterHeader(Expect);
RegisterHeader(Host);
......
......@@ -247,6 +247,17 @@ TEST(headers_test, content_length)
ASSERT_TRUE(cl.value() == 3495U);
}
TEST(headers_test, authorization_test)
{
Pistache::Http::Header::Authorization au;
std::ostringstream oss;
au.parse("Bearer eyJhbGciOiJIUzUxMiIsInR5cCI6IkpXUyJ9.eyJleHAiOjE1NzA2MzA0MDcsImlhdCI6MTU3MDU0NDAwNywibmFtZSI6IkFkbWluIE5hbWUiLCJzYW1wbGUiOiJUZXN0In0.zLTAAnBftlqccsU-4mL69P4tQl3VhcglMg-d0131JxqX4xSZLlO5xMRrCPBgn_00OxKJ9CQdnpjpuzblNQd2-A");
au.write(oss);
ASSERT_TRUE("Bearer eyJhbGciOiJIUzUxMiIsInR5cCI6IkpXUyJ9.eyJleHAiOjE1NzA2MzA0MDcsImlhdCI6MTU3MDU0NDAwNywibmFtZSI6IkFkbWluIE5hbWUiLCJzYW1wbGUiOiJUZXN0In0.zLTAAnBftlqccsU-4mL69P4tQl3VhcglMg-d0131JxqX4xSZLlO5xMRrCPBgn_00OxKJ9CQdnpjpuzblNQd2-A" == oss.str());
ASSERT_TRUE(au.value() == "Bearer eyJhbGciOiJIUzUxMiIsInR5cCI6IkpXUyJ9.eyJleHAiOjE1NzA2MzA0MDcsImlhdCI6MTU3MDU0NDAwNywibmFtZSI6IkFkbWluIE5hbWUiLCJzYW1wbGUiOiJUZXN0In0.zLTAAnBftlqccsU-4mL69P4tQl3VhcglMg-d0131JxqX4xSZLlO5xMRrCPBgn_00OxKJ9CQdnpjpuzblNQd2-A");
}
TEST(headers_test, expect_test)
{
Pistache::Http::Header::Expect e;
......
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