+ bodyTransferSize = -1;
+ chunkedTransfer = false;
+ _contentDecoder.reset();
+ }
+
+ void tryStartNextRequest()
+ {
+ while( !queuedRequests.empty()
+ && queuedRequests.front()->isComplete() )
+ queuedRequests.pop_front();
+
+ if (queuedRequests.empty()) {
+ idleTime.stamp();
+ return;
+ }
+
+ if (sentRequests.size() > MAX_INFLIGHT_REQUESTS) {
+ return;
+ }
+
+ if (state == STATE_CLOSED) {
+ if (!connectToHost()) {
+
+ return;
+ }
+
+ setTerminator("\r\n");
+ state = STATE_IDLE;
+ }
+
+ Request_ptr r = queuedRequests.front();
+ r->requestStart();
+
+ std::stringstream headerData;
+ std::string path = r->path();
+ assert(!path.empty());
+ std::string query = r->query();
+ std::string bodyData;
+
+ if (!client->proxyHost().empty()) {
+ path = r->scheme() + "://" + r->host() + r->path();
+ }
+
+ if (r->bodyType() == CONTENT_TYPE_URL_ENCODED) {
+ headerData << r->method() << " " << path << " HTTP/1.1\r\n";
+ bodyData = query.substr(1); // URL-encode, drop the leading '?'
+ headerData << "Content-Type:" << CONTENT_TYPE_URL_ENCODED << "\r\n";
+ headerData << "Content-Length:" << bodyData.size() << "\r\n";
+ } else {
+ headerData << r->method() << " " << path << query << " HTTP/1.1\r\n";
+ if( r->hasBodyData() )
+ {
+ headerData << "Content-Length:" << r->bodyLength() << "\r\n";
+ headerData << "Content-Type:" << r->bodyType() << "\r\n";
+ }
+ }
+
+ headerData << "Host: " << r->hostAndPort() << "\r\n";
+ headerData << "User-Agent:" << client->userAgent() << "\r\n";
+ headerData << "Accept-Encoding: deflate, gzip\r\n";
+ if (!client->proxyAuth().empty()) {
+ headerData << "Proxy-Authorization: " << client->proxyAuth() << "\r\n";
+ }
+
+ BOOST_FOREACH(const StringMap::value_type& h, r->requestHeaders()) {
+ headerData << h.first << ": " << h.second << "\r\n";
+ }