bool cookieSent = false;
bool sendChunked = false;
+ bool hasBody = true;
if (this->version > 10) { // 1.1 or better
if (headers.find("content-length") == headers.end()) {
}
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;
}
}
}
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";
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);
};
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;
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