diff options
Diffstat (limited to 'Swiften/Network/HTTPConnectProxiedConnection.cpp')
-rw-r--r-- | Swiften/Network/HTTPConnectProxiedConnection.cpp | 17 |
1 files changed, 12 insertions, 5 deletions
diff --git a/Swiften/Network/HTTPConnectProxiedConnection.cpp b/Swiften/Network/HTTPConnectProxiedConnection.cpp index fc5a6c6..942361e 100644 --- a/Swiften/Network/HTTPConnectProxiedConnection.cpp +++ b/Swiften/Network/HTTPConnectProxiedConnection.cpp @@ -80,13 +80,13 @@ void HTTPConnectProxiedConnection::parseHTTPHeader(const std::string& data, std: if (splitIndex != std::string::npos) { headerFields.push_back(std::pair<std::string, std::string>(headerLine.substr(0, splitIndex), headerLine.substr(splitIndex + 1))); } } } -void HTTPConnectProxiedConnection::sendHTTPRequest(const std::string& statusLine, std::vector<std::pair<std::string, std::string> >& headerFields) { +void HTTPConnectProxiedConnection::sendHTTPRequest(const std::string& statusLine, const std::vector<std::pair<std::string, std::string> >& headerFields) { typedef std::pair<std::string, std::string> HTTPHeaderField; std::stringstream request; request << statusLine << "\r\n"; foreach (const HTTPHeaderField& field, headerFields) { request << field.first << ":" << field.second << "\r\n"; @@ -95,27 +95,33 @@ void HTTPConnectProxiedConnection::sendHTTPRequest(const std::string& statusLine write(createSafeByteArray(request.str())); } void HTTPConnectProxiedConnection::handleProxyInitializeData(boost::shared_ptr<SafeByteArray> data) { std::string dataString = byteArrayToString(ByteArray(data->begin(), data->end())); SWIFT_LOG(debug) << data << std::endl; + httpResponseBuffer_.append(dataString); std::string statusLine; std::vector<std::pair<std::string, std::string> > headerFields; - std::string::size_type headerEnd = dataString.find("\r\n\r\n", 0); + std::string::size_type headerEnd = httpResponseBuffer_.find("\r\n\r\n", 0); + if (headerEnd == std::string::npos) { + if ((httpResponseBuffer_.size() > 4) && (httpResponseBuffer_.substr(0, 4) != "HTTP")) { + setProxyInitializeFinished(false); + } + return; + } - parseHTTPHeader(dataString.substr(0, headerEnd), statusLine, headerFields); + parseHTTPHeader(httpResponseBuffer_.substr(0, headerEnd), statusLine, headerFields); if (trafficFilter_) { std::vector<std::pair<std::string, std::string> > newHeaderFields = trafficFilter_->filterHTTPResponseHeader(headerFields); if (!newHeaderFields.empty()) { std::stringstream statusLine; statusLine << "CONNECT " << getServer().getAddress().toString() << ":" << getServer().getPort(); sendHTTPRequest(statusLine.str(), newHeaderFields); - SWIFT_LOG(debug) << "send HTTP request from traffic filter" << std::endl; return; } } std::vector<std::string> tmp = String::split(statusLine, ' '); if (tmp.size() > 1) { @@ -123,19 +129,20 @@ void HTTPConnectProxiedConnection::handleProxyInitializeData(boost::shared_ptr<S int status = boost::lexical_cast<int>(tmp[1]); SWIFT_LOG(debug) << "Proxy Status: " << status << std::endl; if (status / 100 == 2) { // all 2XX states are OK setProxyInitializeFinished(true); } else { - SWIFT_LOG(debug) << "HTTP Proxy returned an error: " << byteArrayToString(ByteArray(data->begin(), data->end())) << std::endl; + SWIFT_LOG(debug) << "HTTP Proxy returned an error: " << httpResponseBuffer_ << std::endl; setProxyInitializeFinished(false); } } catch (boost::bad_lexical_cast&) { SWIFT_LOG(warning) << "Unexpected response: " << tmp[1] << std::endl; setProxyInitializeFinished(false); } } else { setProxyInitializeFinished(false); } + httpResponseBuffer_.clear(); } |