| 66 | |
| 67 | |
| 68 | std::istream* HTTPSStreamFactory::open(const URI& uri) |
| 69 | { |
| 70 | poco_assert (uri.getScheme() == "https" || uri.getScheme() == "http"); |
| 71 | |
| 72 | URI resolvedURI(uri); |
| 73 | URI proxyUri; |
| 74 | HTTPClientSession* pSession = 0; |
| 75 | HTTPResponse res; |
| 76 | try |
| 77 | { |
| 78 | bool retry = false; |
| 79 | bool authorize = false; |
| 80 | int redirects = 0; |
| 81 | std::string username; |
| 82 | std::string password; |
| 83 | |
| 84 | do |
| 85 | { |
| 86 | if (!pSession) |
| 87 | { |
| 88 | if (resolvedURI.getScheme() != "http") |
| 89 | pSession = new HTTPSClientSession(resolvedURI.getHost(), resolvedURI.getPort()); |
| 90 | else |
| 91 | pSession = new HTTPClientSession(resolvedURI.getHost(), resolvedURI.getPort()); |
| 92 | |
| 93 | if (proxyUri.empty()) |
| 94 | { |
| 95 | if (!_proxyHost.empty()) |
| 96 | { |
| 97 | pSession->setProxy(_proxyHost, _proxyPort); |
| 98 | pSession->setProxyCredentials(_proxyUsername, _proxyPassword); |
| 99 | } |
| 100 | } |
| 101 | else |
| 102 | { |
| 103 | pSession->setProxy(proxyUri.getHost(), proxyUri.getPort()); |
| 104 | if (!_proxyUsername.empty()) |
| 105 | { |
| 106 | pSession->setProxyCredentials(_proxyUsername, _proxyPassword); |
| 107 | } |
| 108 | } |
| 109 | } |
| 110 | std::string path = resolvedURI.getPathAndQuery(); |
| 111 | if (path.empty()) path = "/"; |
| 112 | HTTPRequest req(HTTPRequest::HTTP_GET, path, HTTPMessage::HTTP_1_1); |
| 113 | |
| 114 | if (authorize) |
| 115 | { |
| 116 | HTTPCredentials::extractCredentials(uri, username, password); |
| 117 | HTTPCredentials cred(username, password); |
| 118 | cred.authenticate(req, res); |
| 119 | } |
| 120 | |
| 121 | req.set("User-Agent", Poco::format("poco/%d.%d.%d", |
| 122 | (POCO_VERSION >> 24) & 0xFF, |
| 123 | (POCO_VERSION >> 16) & 0xFF, |
| 124 | (POCO_VERSION >> 8) & 0xFF)); |
| 125 | req.set("Accept", "*/*"); |
nothing calls this directly
no test coverage detected