Skip to content

Commit 7476388

Browse files
committed
Merge branch 'master' of https://github.com/xqp/cpprestsdk into xqp-master
2 parents 039b5b9 + a6366cd commit 7476388

File tree

2 files changed

+40
-1
lines changed

2 files changed

+40
-1
lines changed

Release/include/cpprest/http_client.h

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -312,6 +312,35 @@ class http_client_config
312312
}
313313
#endif
314314

315+
/// <summary>
316+
/// Sets a callback to enable custom setting of platform specific options.
317+
/// </summary>
318+
/// <remarks>
319+
/// The native_handle is the following type depending on the underlying platform:
320+
/// Windows Desktop, WinHTTP - HINTERNET
321+
/// Windows Runtime, WinRT - IXMLHTTPRequest2 *
322+
/// All other platforms, Boost.Asio:
323+
/// https - boost::asio::ssl::stream<boost::asio::ip::tcp::socket &> *
324+
/// http - boost::asio::ip::tcp::socket *
325+
/// </remarks>
326+
/// <param name="callback">A user callback allowing for customization of the session</param>
327+
void set_nativesessionhandle_options(const std::function<void(native_handle)> &callback)
328+
{
329+
m_set_user_nativesessionhandle_options = callback;
330+
}
331+
332+
/// <summary>
333+
/// Invokes a user's callback to allow for customization of the session.
334+
/// </summary>
335+
/// <param name="handle">A internal implementation handle.</param>
336+
void invoke_nativesessionhandle_options(native_handle handle) const
337+
{
338+
if (m_set_user_nativesessionhandle_options != nullptr) {
339+
m_set_user_nativesessionhandle_options(handle);
340+
}
341+
}
342+
343+
315344
/// <summary>
316345
/// Sets a callback to enable custom setting of platform specific options.
317346
/// </summary>
@@ -397,6 +426,7 @@ class http_client_config
397426
#endif
398427

399428
std::function<void(native_handle)> m_set_user_nativehandle_options;
429+
std::function<void(native_handle)> m_set_user_nativesessionhandle_options;
400430

401431
#if !defined(_WIN32) && !defined(__cplusplus_winrt) || defined(CPPREST_FORCE_HTTP_CLIENT_ASIO)
402432
std::function<void(boost::asio::ssl::context&)> m_ssl_context_callback;

Release/src/http/client/http_client_winhttp.cpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -448,14 +448,23 @@ class winhttp_client : public _http_client_communicator
448448
}
449449
}
450450
#endif
451-
//Enable TLS 1.1 and 1.2
451+
//Enable TLS 1.1 and 1.2
452452
HRESULT result(S_OK);
453453
BOOL win32_result(FALSE);
454454

455455
DWORD secure_protocols(WINHTTP_FLAG_SECURE_PROTOCOL_SSL3 | WINHTTP_FLAG_SECURE_PROTOCOL_TLS1 | WINHTTP_FLAG_SECURE_PROTOCOL_TLS1_1 | WINHTTP_FLAG_SECURE_PROTOCOL_TLS1_2);
456456
win32_result = ::WinHttpSetOption(m_hSession, WINHTTP_OPTION_SECURE_PROTOCOLS, &secure_protocols, sizeof(secure_protocols));
457457
if(FALSE == win32_result){ result = HRESULT_FROM_WIN32(::GetLastError()); }
458458

459+
try
460+
{
461+
client_config().invoke_nativesessionhandle_options(m_hSession);
462+
}
463+
catch (...)
464+
{
465+
return report_failure(_XPLATSTR("Error in session handle callback"));
466+
}
467+
459468
// Register asynchronous callback.
460469
if(WINHTTP_INVALID_STATUS_CALLBACK == WinHttpSetStatusCallback(
461470
m_hSession,

0 commit comments

Comments
 (0)