Allow iteration over headers

This commit is contained in:
Alex Hultman
2019-03-10 12:43:31 +01:00
parent 1680046963
commit 0212ee5bd0
+30
View File
@@ -48,6 +48,36 @@ public:
return didYield;
}
/* Iteration over headers (key, value) */
struct HeaderIterator {
Header *ptr;
bool operator!=(const HeaderIterator &other) const {
/* Comparison with end is a special case */
if (ptr != other.ptr) {
return other.ptr || ptr->key.length();
}
return false;
}
HeaderIterator &operator++() {
ptr++;
return *this;
}
std::pair<std::string_view, std::string_view> operator*() const {
return {ptr->key, ptr->value};
}
};
HeaderIterator begin() {
return {headers};
}
HeaderIterator end() {
return {nullptr};
}
/* If you do not want to handle this route */
void setYield(bool yield) {
didYield = yield;