17 #include "connectionhttpproxy.h"
33 const std::string& server,
int port )
35 m_logInstance( logInstance ), m_http11( false )
46 const std::string& server,
int port )
48 m_logInstance( logInstance )
74 m_connection = connection;
79 if( m_connection && m_handler )
98 return m_connection->
recv( timeout );
106 return m_connection->
receive();
114 return m_connection->
send( data );
139 const std::string& data )
146 m_proxyHandshakeBuffer += data;
147 if( ( m_proxyHandshakeBuffer.substr( 0, 12 ) ==
"HTTP/1.0 200"
148 || m_proxyHandshakeBuffer.substr( 0, 12 ) ==
"HTTP/1.1 200" )
149 && m_proxyHandshakeBuffer.substr( m_proxyHandshakeBuffer.length() - 4 ) ==
"\r\n\r\n" )
151 m_proxyHandshakeBuffer =
"";
154 "http proxy connection established" );
157 else if( m_proxyHandshakeBuffer.substr( 9, 3 ) ==
"407" )
162 else if( m_proxyHandshakeBuffer.substr( 9, 3 ) ==
"403" ||
163 m_proxyHandshakeBuffer.substr( 9, 3 ) ==
"404" )
177 std::string
server = m_server;
184 server = (*(servers.begin())).first;
185 port = (*(servers.begin())).second;
189 std::ostringstream oss;
190 oss <<
"requesting http proxy connection to " << server <<
":" << port;
193 std::ostringstream os;
194 os <<
"CONNECT " << server <<
":" << port << ( m_http11 ?
" HTTP/1.1" :
" HTTP/1.0" ) <<
"\r\n";
195 os <<
"Host: " << server <<
"\r\n";
196 os <<
"Content-Length: 0\r\n";
197 os <<
"Proxy-Connection: Keep-Alive\r\n";
198 os <<
"Pragma: no-cache\r\n";
199 if( !m_proxyUser.empty() && !m_proxyPassword.empty() )
201 os <<
"Proxy-Authorization: Basic " <<
Base64::encode64( m_proxyUser +
":" + m_proxyPassword )
206 if( !m_connection->
send( os.str() ) )