From 0212ee5bd04a0320a3422a5acafe29730e264f57 Mon Sep 17 00:00:00 2001 From: Alex Hultman Date: Sun, 10 Mar 2019 12:43:31 +0100 Subject: [PATCH] Allow iteration over headers --- src/HttpParser.h | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/src/HttpParser.h b/src/HttpParser.h index 2d6545f..fa7bbeb 100644 --- a/src/HttpParser.h +++ b/src/HttpParser.h @@ -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 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;