Connection::Connection(HttpContext &context, const std::string &scheme, const std::string &host, int port) : _scheme(scheme), _host(host), _port(port), _context(context), _resolver(context.service()), _connected(false), _busy(false) { std::string schemeAddress; #ifdef WINVER std::string proxyAddress; WINHTTP_CURRENT_USER_IE_PROXY_CONFIG proxy; if (WinHttpGetIEProxyConfigForCurrentUser(&proxy)) { if (proxy.lpszProxy) { proxyAddress = boost::locale::conv::utf_to_utf<char>(proxy.lpszProxy); GlobalFree(proxy.lpszProxy); } if (proxy.lpszProxyBypass) { GlobalFree(proxy.lpszProxyBypass); } if (proxy.lpszAutoConfigUrl) { GlobalFree(proxy.lpszProxyBypass); } } enum State { Key, Value } state = Key; std::string key; std::string value; std::map<std::string, std::string> list; for (auto c : proxyAddress) { switch (state) { case Key: if (c == '=') state = Value; else key += c; break; case Value: if (c == ';') { list[key] = value; key = ""; value = ""; state = Key; } else value += c; break; } } if (!value.empty()) list[key] = value; if (list.size() == 0) { schemeAddress = proxyAddress; } else { auto it = list.find(scheme); if (it != list.end()) schemeAddress = it->second; } #else char * data = getenv("https_proxy"); if (data) schemeAddress = data; #endif if (!schemeAddress.empty()) { Url proxyUrl(schemeAddress); _proxy = proxyUrl.host(); _proxyPort = proxyUrl.port(); auto url = host + ":" + boost::lexical_cast<std::string>(port); _proxyGreeting = "CONNECT " + url + " HTTP/1.1\r\n"+ "Host: " + url + "\r\n" + "Connection: Keep-Alive\r\n" + "User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/49.0.2623.112 Safari/537.36\r\n" + "\r\n"; } }
SslConnection::SslConnection(HttpContext &context, const std::string &host, int port) : Connection(context, "https", host, port == 0 ? 443 : port), _socket(context.service(), context.ssl()), _resolver(context.service()) {}