wsd: http: define streaming operators

Change-Id: I911951cb29fe22103076af9f082e3a6eae3c6189
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
This commit is contained in:
Ashod Nakashian 2021-03-14 16:34:25 -04:00 committed by Ashod Nakashian
parent c38e876978
commit 688fefcbda
2 changed files with 44 additions and 2 deletions

View file

@ -333,7 +333,6 @@ int64_t Response::readData(const char* p, int64_t len)
switch (_statusLine.parse(p, read))
{
case FieldParseState::Unknown:
case FieldParseState::Complete:
case FieldParseState::Incomplete:
return 0;
case FieldParseState::Invalid:

View file

@ -9,6 +9,7 @@
#include <chrono>
#include <cstdint>
#include <iostream>
#include <fstream>
#include <memory>
#include <sstream>
@ -136,7 +137,6 @@ enum class FieldParseState
Unknown, //< Not yet parsed.
Incomplete, //< Not enough data to parse this field. Need more data.
Invalid, //< The field is invalid/unexpected/long.
Complete, //< The field is complete. Doesn't imply it's valid.
Valid //< The field is both complete and valid.
};
@ -946,4 +946,47 @@ private:
} // namespace http
#define CASE(X) \
case X: \
os << #X; \
break;
inline std::ostream& operator<<(std::ostream& os, const http::FieldParseState& fieldParseState)
{
switch (fieldParseState)
{
CASE(http::FieldParseState::Unknown);
CASE(http::FieldParseState::Incomplete);
CASE(http::FieldParseState::Invalid);
CASE(http::FieldParseState::Valid);
}
return os;
}
inline std::ostream& operator<<(std::ostream& os, const http::Request::Stage& stage)
{
switch (stage)
{
CASE(http::Request::Stage::Body);
CASE(http::Request::Stage::Finished);
CASE(http::Request::Stage::Header);
}
return os;
}
inline std::ostream& operator<<(std::ostream& os, const http::Response::State& state)
{
switch (state)
{
CASE(http::Response::State::New);
CASE(http::Response::State::Incomplete);
CASE(http::Response::State::Error);
CASE(http::Response::State::Timeout);
CASE(http::Response::State::Complete);
}
return os;
}
#undef CASE
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */