@@ -1120,6 +1120,7 @@ private void SetSessionHandleOptions(SafeWinHttpHandle sessionHandle)
11201120 SetSessionHandleTimeoutOptions ( sessionHandle ) ;
11211121 SetDisableHttp2StreamQueue ( sessionHandle ) ;
11221122 SetTcpKeepalive ( sessionHandle ) ;
1123+ SetRequireStreamEnd ( sessionHandle ) ;
11231124 }
11241125
11251126 private unsafe void SetTcpKeepalive ( SafeWinHttpHandle sessionHandle )
@@ -1145,6 +1146,27 @@ private unsafe void SetTcpKeepalive(SafeWinHttpHandle sessionHandle)
11451146 }
11461147 }
11471148
1149+ private void SetRequireStreamEnd ( SafeWinHttpHandle sessionHandle )
1150+ {
1151+ if ( WinHttpTrailersHelper . OsSupportsTrailers )
1152+ {
1153+ // Setting WINHTTP_OPTION_REQUIRE_STREAM_END to TRUE is needed for WinHttp to read trailing headers
1154+ // in case the response has Content-Lenght defined.
1155+ // According to the WinHttp team, the feature-detection logic in WinHttpTrailersHelper.OsSupportsTrailers
1156+ // should also indicate the support of WINHTTP_OPTION_REQUIRE_STREAM_END.
1157+ // WINHTTP_OPTION_REQUIRE_STREAM_END doesn't have effect on HTTP 1.1 requests, therefore it's safe to set it on
1158+ // the session handle so it is inhereted by all request handles.
1159+ uint optionData = 1 ;
1160+ if ( ! Interop . WinHttp . WinHttpSetOption ( sessionHandle , Interop . WinHttp . WINHTTP_OPTION_REQUIRE_STREAM_END , ref optionData ) )
1161+ {
1162+ if ( NetEventSource . Log . IsEnabled ( ) )
1163+ {
1164+ NetEventSource . Info ( this , "Failed to enable WINHTTP_OPTION_REQUIRE_STREAM_END error code: " + Marshal . GetLastWin32Error ( ) ) ;
1165+ }
1166+ }
1167+ }
1168+ }
1169+
11481170 private void SetSessionHandleConnectionOptions ( SafeWinHttpHandle sessionHandle )
11491171 {
11501172 uint optionData = ( uint ) _maxConnectionsPerServer ;
@@ -1534,22 +1556,6 @@ private void SetRequestHandleHttp2Options(SafeWinHttpHandle requestHandle, Versi
15341556 {
15351557 if ( NetEventSource . Log . IsEnabled ( ) ) NetEventSource . Info ( this , "HTTP/2 option not supported" ) ;
15361558 }
1537-
1538- if ( requestVersion == HttpVersion20 && WinHttpTrailersHelper . OsSupportsTrailers )
1539- {
1540- // Setting WINHTTP_OPTION_REQUIRE_STREAM_END to TRUE is needed for WinHttp to read trailing headers
1541- // in case the response has Content-Lenght defined.
1542- // According to the WinHttp team, the feature-detection logic in WinHttpTrailersHelper.OsSupportsTrailers
1543- // should also indicate the support of WINHTTP_OPTION_REQUIRE_STREAM_END.
1544- optionData = 1 ;
1545- if ( ! Interop . WinHttp . WinHttpSetOption ( requestHandle , Interop . WinHttp . WINHTTP_OPTION_REQUIRE_STREAM_END , ref optionData ) )
1546- {
1547- if ( NetEventSource . Log . IsEnabled ( ) )
1548- {
1549- NetEventSource . Info ( this , "Failed to enable WINHTTP_OPTION_REQUIRE_STREAM_END error code: " + Marshal . GetLastWin32Error ( ) ) ;
1550- }
1551- }
1552- }
15531559 }
15541560
15551561 private void SetWinHttpOption ( SafeWinHttpHandle handle , uint option , ref uint optionData )
0 commit comments