@@ -67,15 +67,15 @@ namespace
67
67
throw Exception (" Unsupported scheme in URI '" + uri.toString () + " '" , ErrorCodes::UNSUPPORTED_URI_SCHEME);
68
68
}
69
69
70
- HTTPSessionPtr makeHTTPSessionImpl (const std::string & host, UInt16 port, bool https, bool keep_alive, bool resolve_host = true )
70
+ HTTPSessionPtr makeHTTPSessionImpl (const std::string & host, UInt16 port, bool https, bool keep_alive, Poco::Net::Context:: Ptr context, bool resolve_host = true ) /* proton: updated */
71
71
{
72
72
HTTPSessionPtr session;
73
73
74
74
if (https)
75
75
{
76
76
#if USE_SSL
77
77
// / Cannot resolve host in advance, otherwise SNI won't work in Poco.
78
- session = std::make_shared<Poco::Net::HTTPSClientSession>(host, port);
78
+ session = std::make_shared<Poco::Net::HTTPSClientSession>(host, port, context );
79
79
#else
80
80
throw Exception (" proton was built without HTTPS support" , ErrorCodes::FEATURE_IS_NOT_ENABLED_AT_BUILD_TIME);
81
81
#endif
@@ -108,10 +108,11 @@ namespace
108
108
const UInt16 proxy_port;
109
109
bool proxy_https;
110
110
bool resolve_host;
111
+ Poco::Net::Context::Ptr context; /* proton: updated */
111
112
using Base = PoolBase<Poco::Net::HTTPClientSession>;
112
113
ObjectPtr allocObject () override
113
114
{
114
- auto session = makeHTTPSessionImpl (host, port, https, true , resolve_host);
115
+ auto session = makeHTTPSessionImpl (host, port, https, true , context, resolve_host);
115
116
if (!proxy_host.empty ())
116
117
{
117
118
const String proxy_scheme = proxy_https ? " https" : " http" ;
@@ -136,6 +137,12 @@ namespace
136
137
const std::string & proxy_host_,
137
138
UInt16 proxy_port_,
138
139
bool proxy_https_,
140
+ // / proton: starts
141
+ const String & private_key_file,
142
+ const String & certificate_file,
143
+ const String & ca_location,
144
+ Poco::Net::Context::VerificationMode verification_mode,
145
+ // / proton: ends
139
146
size_t max_pool_size_,
140
147
bool resolve_host_ = true )
141
148
: Base(static_cast <unsigned >(max_pool_size_), &Poco::Logger::get (" HTTPSessionPool" ))
@@ -146,6 +153,14 @@ namespace
146
153
, proxy_port(proxy_port_)
147
154
, proxy_https(proxy_https_)
148
155
, resolve_host(resolve_host_)
156
+ , context(new Poco::Net::Context(
157
+ Poco::Net::SSLManager::instance ().defaultClientContext()->usage(),
158
+ private_key_file,
159
+ certificate_file,
160
+ ca_location,
161
+ /* verificationMode=*/ verification_mode,
162
+ /* verificationDepth=*/ 9,
163
+ /* loadDefaultCAs=*/ true))
149
164
{
150
165
}
151
166
};
@@ -162,10 +177,21 @@ namespace
162
177
UInt16 proxy_port;
163
178
bool is_proxy_https;
164
179
180
+ // / proton: starts
181
+ String private_key_file;
182
+ String certificate_file;
183
+ String ca_location;
184
+ Poco::Net::Context::VerificationMode Verification_mode;
185
+ // / proton: ends
186
+
165
187
bool operator ==(const Key & rhs) const
166
188
{
167
- return std::tie (target_host, target_port, is_target_https, proxy_host, proxy_port, is_proxy_https)
168
- == std::tie (rhs.target_host , rhs.target_port , rhs.is_target_https , rhs.proxy_host , rhs.proxy_port , rhs.is_proxy_https );
189
+ // / proton: starts
190
+ return std::tie (target_host, target_port, is_target_https, proxy_host, proxy_port, is_proxy_https,
191
+ private_key_file, certificate_file, ca_location, Verification_mode)
192
+ == std::tie (rhs.target_host , rhs.target_port , rhs.is_target_https , rhs.proxy_host , rhs.proxy_port , rhs.is_proxy_https ,
193
+ rhs.private_key_file , rhs.certificate_file , rhs.ca_location , rhs.Verification_mode );
194
+ // / proton: ends
169
195
}
170
196
};
171
197
@@ -204,6 +230,12 @@ namespace
204
230
Entry getSession (
205
231
const Poco::URI & uri,
206
232
const Poco::URI & proxy_uri,
233
+ // / proton: starts
234
+ const String & private_key_file,
235
+ const String & certificate_file,
236
+ const String & ca_location,
237
+ Poco::Net::Context::VerificationMode verification_mode,
238
+ // / proton: ends
207
239
const ConnectionTimeouts & timeouts,
208
240
size_t max_connections_per_endpoint,
209
241
bool resolve_host = true )
@@ -224,11 +256,16 @@ namespace
224
256
proxy_https = isHTTPS (proxy_uri);
225
257
}
226
258
227
- HTTPSessionPool::Key key{host, port, https, proxy_host, proxy_port, proxy_https};
259
+ HTTPSessionPool::Key key{
260
+ host, port, https, proxy_host, proxy_port, proxy_https,
261
+ private_key_file, certificate_file, ca_location, verification_mode};
228
262
auto pool_ptr = endpoints_pool.find (key);
229
263
if (pool_ptr == endpoints_pool.end ())
230
264
std::tie (pool_ptr, std::ignore) = endpoints_pool.emplace (
231
- key, std::make_shared<SingleEndpointHTTPSessionPool>(host, port, https, proxy_host, proxy_port, proxy_https, max_connections_per_endpoint, resolve_host));
265
+ key, std::make_shared<SingleEndpointHTTPSessionPool>(
266
+ host, port, https, proxy_host, proxy_port, proxy_https,
267
+ private_key_file, certificate_file, ca_location, verification_mode, /* proton: updated */
268
+ max_connections_per_endpoint, resolve_host));
232
269
233
270
auto retry_timeout = timeouts.connection_timeout .totalMicroseconds ();
234
271
auto session = pool_ptr->second ->get (retry_timeout);
@@ -280,20 +317,60 @@ HTTPSessionPtr makeHTTPSession(const Poco::URI & uri, const ConnectionTimeouts &
280
317
UInt16 port = uri.getPort ();
281
318
bool https = isHTTPS (uri);
282
319
283
- auto session = makeHTTPSessionImpl (host, port, https, false , resolve_host);
320
+ auto session = makeHTTPSessionImpl (host, port, https, false , Poco::Net::SSLManager::instance (). defaultClientContext (), resolve_host);
284
321
setTimeouts (*session, timeouts);
285
322
return session;
286
323
}
287
324
325
+ // / proton: starts
326
+ PooledHTTPSessionPtr makePooledHTTPSession (
327
+ const Poco::URI & uri,
328
+ const String & private_key_file,
329
+ const String & certificate_file,
330
+ const String & ca_location,
331
+ Poco::Net::Context::VerificationMode verification_mode,
332
+ const ConnectionTimeouts & timeouts,
333
+ size_t per_endpoint_pool_size,
334
+ bool resolve_host)
335
+ {
336
+ return makePooledHTTPSession (uri, {},
337
+ private_key_file, certificate_file, ca_location, verification_mode,
338
+ timeouts, per_endpoint_pool_size, resolve_host);
339
+ }
340
+
341
+ PooledHTTPSessionPtr makePooledHTTPSession (
342
+ const Poco::URI & uri,
343
+ const Poco::URI & proxy_uri,
344
+ const String & private_key_file,
345
+ const String & certificate_file,
346
+ const String & ca_location,
347
+ Poco::Net::Context::VerificationMode verification_mode,
348
+ const ConnectionTimeouts & timeouts,
349
+ size_t per_endpoint_pool_size,
350
+ bool resolve_host)
351
+ {
352
+ return HTTPSessionPool::instance ().getSession (uri, proxy_uri,
353
+ private_key_file, certificate_file, ca_location, verification_mode,
354
+ timeouts, per_endpoint_pool_size, resolve_host);
355
+ }
356
+ // / proton: ends
357
+
288
358
289
359
PooledHTTPSessionPtr makePooledHTTPSession (const Poco::URI & uri, const ConnectionTimeouts & timeouts, size_t per_endpoint_pool_size, bool resolve_host)
290
360
{
291
361
return makePooledHTTPSession (uri, {}, timeouts, per_endpoint_pool_size, resolve_host);
292
362
}
293
363
294
- PooledHTTPSessionPtr makePooledHTTPSession (const Poco::URI & uri, const Poco::URI & proxy_uri, const ConnectionTimeouts & timeouts, size_t per_endpoint_pool_size, bool resolve_host)
364
+ PooledHTTPSessionPtr makePooledHTTPSession (
365
+ const Poco::URI & uri,
366
+ const Poco::URI & proxy_uri,
367
+ const ConnectionTimeouts & timeouts,
368
+ size_t per_endpoint_pool_size,
369
+ bool resolve_host)
295
370
{
296
- return HTTPSessionPool::instance ().getSession (uri, proxy_uri, timeouts, per_endpoint_pool_size, resolve_host);
371
+ return HTTPSessionPool::instance ().getSession (uri, proxy_uri,
372
+ /* private_key_file=*/ " " , /* certificate_file=*/ " " , /* ca_location=*/ " " , /* verification_mode=*/ Poco::Net::Context::VERIFY_RELAXED,
373
+ timeouts, per_endpoint_pool_size, resolve_host);
297
374
}
298
375
299
376
bool isRedirect (const Poco::Net::HTTPResponse::HTTPStatus status) { return status == Poco::Net::HTTPResponse::HTTP_MOVED_PERMANENTLY || status == Poco::Net::HTTPResponse::HTTP_FOUND || status == Poco::Net::HTTPResponse::HTTP_SEE_OTHER || status == Poco::Net::HTTPResponse::HTTP_TEMPORARY_REDIRECT; }
0 commit comments