asp.net-coresslhttp2http-1.1

Send HTTP_1_1_REQUIRED from ASP.NET Core controller


I need to request client to downgrade http protocol version from 2 to 1.1. Is it possible to send HTTP_1_1_REQUIRED from ASP.NET Core controller. For me it seems that this can be done only on some lower level than we can access in such a controller. But I was told that HttpReceiveClientCertificate does this in case it can't find the certificate.


Solution

  • Yes, it's possible with the help of the IHttpResetFeature interface.

    Keep in mind that it works only if Windows has HttpSetRequestProperty in httpapi.dll (Windows 10 and Windows Server 2016 don't have it).

    If you need to support older OSes and you need HTTP_1_1_REQUIRED only to request a client certificate, AND if you are using HTTP.sys for hosting of your webapp, you can call the HttpReceiveClientCertificate API you mentioned - it will reset HTTP/2 connection with HTTP_1_1_REQUIRED reset code.

    I did it via calling internal Request.GetClientCertificateAsync method via reflection. You can read a bit more about this approach in this answer.