WinHttpHandler callbacks to access arbitrary native WinHTTP options #42592
Labels
api-suggestion
Early API idea and discussion, it is NOT ready for implementation
area-System.Net.Http
Milestone
Background and Motivation
As described in #39210, we have several user scenarios which can be addressed by utilizing new native WinHTTP options. The Windows team iterates relatively fast on them, it's not always realistic and reasonable to introduce managed API-s for every new option.
Instead, I'm proposing an API to access the native Session and Request
HINTERNET
handles, enabling the execution of arbitraryWinHttpSetOption
andWinHttpQueryOption
P/Invokes for advanced users.Challanges
WinHttpHandler
, however it is being instantiated in a lazy waySendAsync
call. (It gets created and destroyed transparenty, within the call)SendAsync
call. For example:WINHTTP_OPTION_CONNECTION_STATS_V0
only makes sense after the request have been sent.WINHTTP_OPTION_REQUEST_STATS
allows observing some characteristics of the response. This could be only done after the response has been received.Proposed API
I'm proposing a callback-based model to address the lifecycle challenges. Hooking into specific events of the handle lifecycle allows a flexible way to observe/change the behavior of
WinHttpHandler
.Usage Examples
The following code observes the time since the the underlying TCP connection has been created by querying
WINHTTP_OPTION_CONNECTION_STATS_V0
, forcing the creation of a new TCP connection after some time elapsed. (This is very similar, but probably not identical to an actual use-case AFAIK.)Alternative Designs
protected virtual
methods instad of callbacksRisks
It doesn't seem trivial to me whethere there is a "right spot" to invoke the
RequestSentCallback
andResponseReceivedCallback
to enable querying/setting any current and future option. A mistake here can lead to breaking changes or the need for further callbacks.runtime/src/libraries/System.Net.Http.WinHttpHandler/src/System/Net/Http/WinHttpHandler.cs
Lines 870 to 911 in 0d62c36
The text was updated successfully, but these errors were encountered: