Repository: dotnet/aspnetcore
File: src/Servers/IIS/IIS/src/Core/IISHttpContext.cs (C#)

Code before:
        return RequestHeaders.ContentLength.GetValueOrDefault() > 0;
    }

    private void GetTlsHandshakeResults()
    {
        var handshake = GetTlsHandshake();
        Protocol = (SslProtocols)handshake.Protocol;

        NegotiatedCipherSuite = GetTlsCipherSuite();
#pragma warning disable SYSLIB0058 // Type or member is obsolete
        CipherAlgorithm = (CipherAlgorithmType)handshake.CipherType;
        CipherStrength = (int)handshake.CipherStrength;
        HashAlgorithm = (HashAlgorithmType)handshake.HashType;
        HashStrength = (int)handshake.HashStrength;
        KeyExchangeAlgorithm = (ExchangeAlgorithmType)handshake.KeyExchangeType;
        KeyExchangeStrength = (int)handshake.KeyExchangeStrength;
#pragma warning restore SYSLIB0058 // Type or member is obsolete

        var sni = GetClientSni();
        SniHostName = sni.Hostname.ToString();
    }

    private unsafe TlsCipherSuite? GetTlsCipherSuite()
    {
        var size = sizeof(SecPkgContext_CipherInfo);
        var buffer = new byte[size];

        fixed (byte* pBuffer = buffer)
        {
            var statusCode = NativeMethods.HttpQueryRequestProperty(
                RequestId,
                (HTTP_REQUEST_PROPERTY)14 /* HTTP_REQUEST_PROPERTY.HttpRequestPropertyTlsCipherInfo */,
                qualifier: null,
                qualifierSize: 0,
                (void*)pBuffer,
                (uint)buffer.Length,
                bytesReturned: null,
                IntPtr.Zero);

            if (statusCode == NativeMethods.HR_OK)
            {
                var cipherInfo = Marshal.PtrToStructure<SecPkgContext_CipherInfo>((IntPtr)pBuffer);
                return (TlsCipherSuite)cipherInfo.dwCipherSuite;
            }

            return default;
        }
    }

    private unsafe HTTP_REQUEST_PROPERTY_SNI GetClientSni()
    {

Review comment (suggestion):
For Http.Sys you defined the SecPkgContext_CipherInfo on the stack, but in IIS you're allocating a new array.

Since you're already `unsafe`, the Http.Sys approach is better.

Code after:
    }

    private void GetTlsHandshakeResults()
    {
        var handshake = GetTlsHandshake();
        Protocol = (SslProtocols)handshake.Protocol;

        NegotiatedCipherSuite = GetTlsCipherSuite();
#pragma warning disable SYSLIB0058 // Type or member is obsolete
        CipherAlgorithm = (CipherAlgorithmType)handshake.CipherType;
        CipherStrength = (int)handshake.CipherStrength;
        HashAlgorithm = (HashAlgorithmType)handshake.HashType;
        HashStrength = (int)handshake.HashStrength;
        KeyExchangeAlgorithm = (ExchangeAlgorithmType)handshake.KeyExchangeType;
        KeyExchangeStrength = (int)handshake.KeyExchangeStrength;
#pragma warning restore SYSLIB0058 // Type or member is obsolete

        var sni = GetClientSni();
        SniHostName = sni.Hostname.ToString();
    }

    private unsafe TlsCipherSuite? GetTlsCipherSuite()
    {
        SecPkgContext_CipherInfo cipherInfo = default;

        var statusCode = NativeMethods.HttpQueryRequestProperty(
            RequestId,
            (HTTP_REQUEST_PROPERTY)14 /* HTTP_REQUEST_PROPERTY.HttpRequestPropertyTlsCipherInfo */,
            qualifier: null,
            qualifierSize: 0,
            output: &cipherInfo,
            outputSize: (uint)sizeof(SecPkgContext_CipherInfo),
            bytesReturned: null,
            overlapped: IntPtr.Zero);

        if (statusCode == NativeMethods.HR_OK)
        {
            return checked((TlsCipherSuite)cipherInfo.dwCipherSuite);
        }

        return default;
    }

    private unsafe HTTP_REQUEST_PROPERTY_SNI GetClientSni()
    {
        var buffer = new byte[HttpApiTypes.SniPropertySizeInBytes];
        fixed (byte* pBuffer = buffer)
        {
            var statusCode = NativeMethods.HttpQueryRequestProperty(
                RequestId,
                HTTP_REQUEST_PROPERTY.HttpRequestPropertySni,