From d4a96ba2b21f7188c0c2941a5f108536c795c1a6 Mon Sep 17 00:00:00 2001 From: Aki Tuomi Date: Thu, 18 Jun 2015 17:34:09 +0300 Subject: [PATCH] Update YaHTTP to v0.1.6 --- pdns/ext/yahttp/yahttp/reqresp.cpp | 14 ++++++++------ pdns/ext/yahttp/yahttp/reqresp.hpp | 18 ++++++++++++++++++ pdns/ext/yahttp/yahttp/router.hpp | 2 +- 3 files changed, 27 insertions(+), 7 deletions(-) diff --git a/pdns/ext/yahttp/yahttp/reqresp.cpp b/pdns/ext/yahttp/yahttp/reqresp.cpp index 07a408a34..eee72804b 100644 --- a/pdns/ext/yahttp/yahttp/reqresp.cpp +++ b/pdns/ext/yahttp/yahttp/reqresp.cpp @@ -188,6 +188,7 @@ namespace YaHTTP { bool cookieSent = false; bool sendChunked = false; + bool hasBody = true; if (this->version > 10) { // 1.1 or better if (headers.find("content-length") == headers.end()) { @@ -198,16 +199,16 @@ namespace YaHTTP { } if ((headers.find("transfer-encoding") == headers.end() && kind == YAHTTP_TYPE_RESPONSE)) { sendChunked = true; - // write the header now - os << "Transfer-Encoding: chunked" << "\r\n"; + os << "Transfer-Encoding: chunked\r\n"; } } else { + hasBody = (headers.find("content-length")->second != "0"); if ((headers.find("transfer-encoding") == headers.end() && kind == YAHTTP_TYPE_RESPONSE)) { - sendChunked = true; - // write the header now - os << "Transfer-Encoding: chunked" << "\r\n"; + sendChunked = hasBody; + if (sendChunked) + os << "Transfer-Encoding: chunked\r\n"; } else if (headers.find("transfer-encoding") != headers.end() && headers.find("transfer-encoding")->second == "chunked") { - sendChunked = true; + sendChunked = hasBody; } } } @@ -216,6 +217,7 @@ namespace YaHTTP { strstr_map_t::const_iterator iter = headers.begin(); while(iter != headers.end()) { if (iter->first == "host" && kind != YAHTTP_TYPE_REQUEST) { iter++; continue; } + if (iter->first == "transfer-encoding" && sendChunked) { iter++; continue; } std::string header = Utility::camelizeHeader(iter->first); if (header == "Cookie" || header == "Set-Cookie") cookieSent = true; os << Utility::camelizeHeader(iter->first) << ": " << iter->second << "\r\n"; diff --git a/pdns/ext/yahttp/yahttp/reqresp.hpp b/pdns/ext/yahttp/yahttp/reqresp.hpp index 8916c8e71..9419d556f 100644 --- a/pdns/ext/yahttp/yahttp/reqresp.hpp +++ b/pdns/ext/yahttp/yahttp/reqresp.hpp @@ -206,6 +206,15 @@ public: HTTPBase::initialize(); this->kind = YAHTTP_TYPE_RESPONSE; } + void initialize(const HTTPBase& rhs) { + HTTPBase::initialize(); + this->kind = YAHTTP_TYPE_RESPONSE; + // copy SOME attributes + this->url = rhs.url; + this->method = rhs.method; + this->jar = rhs.jar; + this->version = rhs.version; + } friend std::ostream& operator<<(std::ostream& os, const Response &resp); friend std::istream& operator>>(std::istream& is, Response &resp); }; @@ -226,6 +235,15 @@ public: HTTPBase::initialize(); this->kind = YAHTTP_TYPE_REQUEST; } + void initialize(const HTTPBase& rhs) { + HTTPBase::initialize(); + this->kind = YAHTTP_TYPE_REQUEST; + // copy SOME attributes + this->url = rhs.url; + this->method = rhs.method; + this->jar = rhs.jar; + this->version = rhs.version; + } void setup(const std::string& method, const std::string& url) { this->url.parse(url); this->headers["host"] = this->url.host; diff --git a/pdns/ext/yahttp/yahttp/router.hpp b/pdns/ext/yahttp/yahttp/router.hpp index 60bd21725..915155f8a 100644 --- a/pdns/ext/yahttp/yahttp/router.hpp +++ b/pdns/ext/yahttp/yahttp/router.hpp @@ -17,7 +17,7 @@ namespace funcptr = std; namespace funcptr = boost; #define HAVE_CPP_FUNC_PTR #else -#warn "You need to configure with boost or have C++11 capable compiler for router" +#warning "You need to configure with boost or have C++11 capable compiler for router" #endif #endif -- 2.40.0