diff options
author | Tobias Markmann <tm@ayena.de> | 2015-03-17 12:55:12 (GMT) |
---|---|---|
committer | Kevin Smith <kevin.smith@isode.com> | 2015-03-19 18:44:21 (GMT) |
commit | cd193389d65c4abd51c557f942348f36356f4788 (patch) | |
tree | 77f6fea1542cc1f9dba6c299f74dc3bfbe0b1dde /Swiften/Network/HTTPConnectProxiedConnection.cpp | |
parent | fedd8d88befb0fa19a58a78a163c200889b5272c (diff) | |
download | swift-cd193389d65c4abd51c557f942348f36356f4788.zip swift-cd193389d65c4abd51c557f942348f36356f4788.tar.bz2 |
Fix for HTTPConnectProxiedConnection to support responses in pieces
This fix lets HTTPConnectProxiedConnection buffer response data in
pieces until the end of the HTTP header is reached. Only then it will
try to parse the HTTP header.
This is *not* the HTTP chunked transfer encoding.
Test-Information:
Adjusted one test to respond in pieces and added a new test case that
verifies that response data is buffered.
Change-Id: Icfb987bdf2fc5771401a8a9c6979fa9ad1eebdca
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 @@ -83,7 +83,7 @@ void HTTPConnectProxiedConnection::parseHTTPHeader(const std::string& data, std: } } -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; @@ -98,13 +98,20 @@ void HTTPConnectProxiedConnection::sendHTTPRequest(const std::string& statusLine 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); @@ -112,7 +119,6 @@ void HTTPConnectProxiedConnection::handleProxyInitializeData(boost::shared_ptr<S 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; } } @@ -126,7 +132,7 @@ void HTTPConnectProxiedConnection::handleProxyInitializeData(boost::shared_ptr<S 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); } } @@ -138,4 +144,5 @@ void HTTPConnectProxiedConnection::handleProxyInitializeData(boost::shared_ptr<S else { setProxyInitializeFinished(false); } + httpResponseBuffer_.clear(); } |