@@ -904,6 +904,14 @@ private async Task StartRequestAsync(WinHttpRequestState state)
904904 {
905905 httpVersion = "HTTP/1.1" ;
906906 }
907+ else if ( state . RequestMessage . Version == HttpVersion20 )
908+ {
909+ httpVersion = "HTTP/2.0" ;
910+ }
911+ else if ( state . RequestMessage . Version == HttpVersion30 )
912+ {
913+ httpVersion = "HTTP/3.0" ;
914+ }
907915
908916 OpenRequestHandle ( state , connectHandle , httpVersion , out WinHttpChunkMode chunkedModeForSend , out SafeWinHttpHandle requestHandle ) ;
909917 state . RequestHandle = requestHandle ;
@@ -1269,7 +1277,7 @@ private void SetRequestHandleOptions(WinHttpRequestState state)
12691277 SetRequestHandleClientCertificateOptions ( state . RequestHandle , state . RequestMessage . RequestUri ) ;
12701278 SetRequestHandleCredentialsOptions ( state ) ;
12711279 SetRequestHandleBufferingOptions ( state . RequestHandle ) ;
1272- SetRequestHandleHttpProtocolOptions ( state . RequestHandle , state . RequestMessage . Version ) ;
1280+ SetRequestHandleHttpProtocolOptions ( state . RequestHandle , state . RequestMessage . Version , state . RequestMessage . VersionPolicy == HttpVersionPolicy . RequestVersionExact ) ;
12731281 }
12741282
12751283 private static void SetRequestHandleProxyOptions ( WinHttpRequestState state )
@@ -1509,7 +1517,7 @@ private void SetRequestHandleBufferingOptions(SafeWinHttpHandle requestHandle)
15091517 SetWinHttpOption ( requestHandle , Interop . WinHttp . WINHTTP_OPTION_MAX_RESPONSE_DRAIN_SIZE , ref optionData ) ;
15101518 }
15111519
1512- private void SetRequestHandleHttpProtocolOptions ( SafeWinHttpHandle requestHandle , Version requestVersion )
1520+ private void SetRequestHandleHttpProtocolOptions ( SafeWinHttpHandle requestHandle , Version requestVersion , bool required )
15131521 {
15141522 Debug . Assert ( requestHandle != null ) ;
15151523 uint optionData = ( requestVersion == HttpVersion30 ) ? Interop . WinHttp . WINHTTP_PROTOCOL_FLAG_HTTP3 :
@@ -1524,6 +1532,19 @@ private void SetRequestHandleHttpProtocolOptions(SafeWinHttpHandle requestHandle
15241532 else
15251533 {
15261534 if ( NetEventSource . Log . IsEnabled ( ) ) NetEventSource . Info ( this , $ "HTTP/{ requestVersion . Major } option not supported") ;
1535+ return ;
1536+ }
1537+
1538+ if ( required && requestVersion >= HttpVersion20 )
1539+ {
1540+ uint protocolRequired = 1 ;
1541+ if ( ! Interop . WinHttp . WinHttpSetOption (
1542+ requestHandle ,
1543+ Interop . WinHttp . WINHTTP_OPTION_HTTP_PROTOCOL_REQUIRED ,
1544+ ref protocolRequired ) )
1545+ {
1546+ if ( NetEventSource . Log . IsEnabled ( ) ) NetEventSource . Info ( this , "HTTP protocol required option not supported" ) ;
1547+ }
15271548 }
15281549 }
15291550
0 commit comments