diff --git a/example/helloworld/main.cpp b/example/helloworld/main.cpp index 60e2c38..2b7c115 100644 --- a/example/helloworld/main.cpp +++ b/example/helloworld/main.cpp @@ -59,7 +59,7 @@ void runServer(const QString& portOrPath) { qPrintable(req->url().toString().toUtf8()) ); qDebug("[Headers (%d)]", h.size()); - qhttp::for_each(h.constBegin(), h.constEnd(), [](auto iter) { + h.forEach([](auto iter) { qDebug(" %s : %s", iter.key().constData(), iter.value().constData() @@ -101,8 +101,7 @@ void runClient(QString url) { // just for fun! print headers: qDebug("\n[Headers:]"); - const auto& hs = res->headers(); - qhttp::for_each(hs.constBegin(), hs.constEnd(), [](auto cit) { + res->headers().forEach([](auto cit) { qDebug("%s : %s", cit.key().constData(), cit.value().constData()); }); }); @@ -145,8 +144,7 @@ void runWeatherClient(const QString& cityName) { // just for fun! print headers: qDebug("\n[Headers:]"); - const auto& hs = res->headers(); - qhttp::for_each(hs.constBegin(), hs.constEnd(), [](auto cit){ + res->headers().forEach([](auto cit) { qDebug("%s : %s", cit.key().constData(), cit.value().constData()); }); }); diff --git a/src/private/httpwriter.hxx b/src/private/httpwriter.hxx index 7440133..910e845 100644 --- a/src/private/httpwriter.hxx +++ b/src/private/httpwriter.hxx @@ -84,12 +84,8 @@ public: TImpl* me = static_cast(this); me->prepareHeadersToWrite(); - qhttp::for_each(TBase::iheaders.constBegin(), TBase::iheaders.constEnd(), - [this](const auto& cit) { - const QByteArray& field = cit.key(); - const QByteArray& value = cit.value(); - - this->writeHeader(field, value); + TBase::iheaders.forEach([this](const auto& cit) { + this->writeHeader(cit.key(), cit.value()); }); isocket.writeRaw("\r\n"); diff --git a/src/qhttpfwd.hpp b/src/qhttpfwd.hpp index f290593..534e687 100644 --- a/src/qhttpfwd.hpp +++ b/src/qhttpfwd.hpp @@ -29,33 +29,38 @@ struct http_parser; namespace qhttp { /////////////////////////////////////////////////////////////////////////////// +/// QHash/QMap iterators are incompatibility with range for +template +void for_each(Iterator first, Iterator last, Func&& f) { + while ( first != last ) { + f( first ); + ++first; + } +} + /** A map of request or response headers. */ class THeaderHash : public QHash { public: /** checks for a header item, regardless of the case of the characters. */ - bool has(const QByteArray& key) const { + bool has(const QByteArray& key) const { return contains(key.toLower()); } /** checks if a header has the specified value ignoring the case of the characters. */ - bool keyHasValue(const QByteArray& key, const QByteArray& value) const { + bool keyHasValue(const QByteArray& key, const QByteArray& value) const { if ( !contains(key) ) return false; const QByteArray& v = QHash::value(key); return qstrnicmp(value.constData(), v.constData(), v.size()) == 0; } -}; -/// QHash/QMap iterators are incompatibility with range for -template -void for_each(Iterator first, Iterator last, Func&& f) { - while ( first != last ) { - f( first ); - ++first; + template + void forEach(Func&& f) const { + for_each(constBegin(), constEnd(), f); } -} +}; /** Request method enumeration.