API Suggestion: Add HttpSys feature interface for fetching TLS ClientHello #61625
Labels
api-suggestion
Early API idea and discussion, it is NOT ready for implementation
area-networking
Includes servers, yarp, json patch, bedrock, websockets, http client factory, and http abstractions
Background and Motivation
API Proposal: Expose TLS client hello message adds a feature to expose the TLS ClientHello message to users on HttpSys and Kestrel. The HttpSys API in that proposal is a callback that is invoked once for every incoming TLS connection. It would be useful to also expose a "get" API, accessible through the HttpContext, that allows users to query the ClientHello on-demand. This API would have the following benefits over the current callback approach:
Users have better control over when/if the ClientHello should be fetched.
It is easier for the user to correlate the ClientHello with the requests flowing over the connection.
The current callback approach leads users down a difficult path:
HttpRequest.RequestAborted
can be used to detect connection closure on HTTP/1.1, it does not work on HTTP/2 - the cancellation token fires whenever the current HTTP/2 stream is completed, not when the TCP connection closes. This means the connection cache needs to use a heuristic approach to tracking connections, and is likely to contain far more connections than are actually active on the web server.Users can choose a CPU/memory tradeoff when using the API.
The API can be called once per request, resulting in higher CPU usage but lower memory usage. Or the API can be called once per connection (by building a connection cache), resulting in lower CPU but higher memory usage.
Proposed API
GetClientHello()
invokes the user-provided callback, passing the Client Hello bytes as aReadOnlySpan<byte>
. The user can also pass in astate
argument, which will be passed directly to the callback. The API shape is modeled after string.Create() and allows the implementation to be allocation-free, since the span can be backed by a pooled array.GetClientHello()
will throw an exception on error.The
IHttpSysRequestPropertiesFeature
naming is based on the name of the underlying Windows http.sysHttpQueryRequestProperty()
API. The idea is that the same feature interface could be used to expose other parts of this Windows API in the future if needed.Usage Examples
Alternative Designs
The API could take a user-provided buffer instead. The user has to guess a buffer size with this approach. If the buffer size is too small, the method returns false and indicates the required size in
bytesRequired
.For any error other than "buffer too small", the API would throw an exception.
Risks
The
HttpQueryRequestProperty()
Windows API takes an LPOVERLAPPED as an argument, allowing async completion. It may be necessary to expose an async API if this routine ever blocks.The text was updated successfully, but these errors were encountered: