Improving coverage for src/common/http_header.cc

parent c2067dec
...@@ -33,4 +33,6 @@ build ...@@ -33,4 +33,6 @@ build
# Ignoring IDE files # Ignoring IDE files
.vscode .vscode
.idea .idea
\ No newline at end of file
libpistache-github.code-workspace
{
"folders": [
{
"path": "."
}
],
"settings": {
"coverage-gutters.showLineCoverage": true,
"coverage-gutters.coverageReportFileName": "build/index.html"
}
}
\ No newline at end of file
...@@ -19,6 +19,22 @@ namespace Pistache { ...@@ -19,6 +19,22 @@ namespace Pistache {
namespace Http { namespace Http {
namespace Header { namespace Header {
void
Header::parse(const std::string & str) {
parseRaw(str.c_str(), str.length());
}
void
Header::parseRaw(const char *str, size_t len) {
parse(std::string(str, len));
}
void
Allow::parseRaw(const char* str, size_t len) {
UNUSED(str)
UNUSED(len)
}
const char* encodingString(Encoding encoding) { const char* encodingString(Encoding encoding) {
switch (encoding) { switch (encoding) {
case Encoding::Gzip: case Encoding::Gzip:
...@@ -32,26 +48,9 @@ const char* encodingString(Encoding encoding) { ...@@ -32,26 +48,9 @@ const char* encodingString(Encoding encoding) {
case Encoding::Chunked: case Encoding::Chunked:
return "chunked"; return "chunked";
case Encoding::Unknown: case Encoding::Unknown:
default:
return "unknown"; return "unknown";
} }
unreachable();
}
void
Header::parse(const std::string& data) {
parseRaw(data.c_str(), data.size());
}
void
Header::parseRaw(const char *str, size_t len) {
parse(std::string(str, len));
}
void
Allow::parseRaw(const char* str, size_t len) {
UNUSED(str)
UNUSED(len)
} }
void void
...@@ -204,7 +203,6 @@ CacheControl::write(std::ostream& os) const { ...@@ -204,7 +203,6 @@ CacheControl::write(std::ostream& os) const {
case CacheDirective::SMaxAge: case CacheDirective::SMaxAge:
return "s-maxage"; return "s-maxage";
case CacheDirective::Ext: case CacheDirective::Ext:
return "";
default: default:
return ""; return "";
} }
...@@ -316,7 +314,7 @@ Date::write(std::ostream& os) const { ...@@ -316,7 +314,7 @@ Date::write(std::ostream& os) const {
void void
Expect::parseRaw(const char* str, size_t len) { Expect::parseRaw(const char* str, size_t len) {
if (memcmp(str, "100-continue", len)) { if (std::strcmp(str, "100-continue") == 0) {
expectation_ = Expectation::Continue; expectation_ = Expectation::Continue;
} else { } else {
expectation_ = Expectation::Ext; expectation_ = Expectation::Ext;
...@@ -508,16 +506,21 @@ Server::Server(const char* token) ...@@ -508,16 +506,21 @@ Server::Server(const char* token)
} }
void void
Server::parse(const std::string& data) Server::parse(const std::string& token)
{ {
UNUSED(data) tokens_.push_back(token);
} }
void void
Server::write(std::ostream& os) const Server::write(std::ostream& os) const
{ {
std::copy(std::begin(tokens_), std::end(tokens_), for (int i = 0; i < tokens_.size(); i++) {
std::ostream_iterator<std::string>(os, " ")); auto & token = tokens_[i];
os << token;
if ( i < tokens_.size() - 1 ) {
os << " ";
}
}
} }
void void
......
This diff is collapsed.
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