Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
set WINHTTP_OPTION_REQUIRE_STREAM_END on the session handle
  • Loading branch information
antonfirsov authored and github-actions committed Jan 4, 2022
commit e6f111c9aa7acb067e0e1da29a46d3a019e3ee58
Original file line number Diff line number Diff line change
Expand Up @@ -1120,6 +1120,7 @@ private void SetSessionHandleOptions(SafeWinHttpHandle sessionHandle)
SetSessionHandleTimeoutOptions(sessionHandle);
SetDisableHttp2StreamQueue(sessionHandle);
SetTcpKeepalive(sessionHandle);
SetRequireStreamEnd(sessionHandle);
}

private unsafe void SetTcpKeepalive(SafeWinHttpHandle sessionHandle)
Expand All @@ -1145,6 +1146,27 @@ private unsafe void SetTcpKeepalive(SafeWinHttpHandle sessionHandle)
}
}

private void SetRequireStreamEnd(SafeWinHttpHandle sessionHandle)
{
if (WinHttpTrailersHelper.OsSupportsTrailers)
{
// Setting WINHTTP_OPTION_REQUIRE_STREAM_END to TRUE is needed for WinHttp to read trailing headers
// in case the response has Content-Lenght defined.
// According to the WinHttp team, the feature-detection logic in WinHttpTrailersHelper.OsSupportsTrailers
// should also indicate the support of WINHTTP_OPTION_REQUIRE_STREAM_END.
// WINHTTP_OPTION_REQUIRE_STREAM_END doesn't have effect on HTTP 1.1 requests, therefore it's safe to set it on
// the session handle so it is inhereted by all request handles.
uint optionData = 1;
if (!Interop.WinHttp.WinHttpSetOption(sessionHandle, Interop.WinHttp.WINHTTP_OPTION_REQUIRE_STREAM_END, ref optionData))
{
if (NetEventSource.Log.IsEnabled())
{
NetEventSource.Info(this, "Failed to enable WINHTTP_OPTION_REQUIRE_STREAM_END error code: " + Marshal.GetLastWin32Error());
}
}
}
}

private void SetSessionHandleConnectionOptions(SafeWinHttpHandle sessionHandle)
{
uint optionData = (uint)_maxConnectionsPerServer;
Expand Down Expand Up @@ -1534,22 +1556,6 @@ private void SetRequestHandleHttp2Options(SafeWinHttpHandle requestHandle, Versi
{
if (NetEventSource.Log.IsEnabled()) NetEventSource.Info(this, "HTTP/2 option not supported");
}

if (requestVersion == HttpVersion20 && WinHttpTrailersHelper.OsSupportsTrailers)
{
// Setting WINHTTP_OPTION_REQUIRE_STREAM_END to TRUE is needed for WinHttp to read trailing headers
// in case the response has Content-Lenght defined.
// According to the WinHttp team, the feature-detection logic in WinHttpTrailersHelper.OsSupportsTrailers
// should also indicate the support of WINHTTP_OPTION_REQUIRE_STREAM_END.
optionData = 1;
if (!Interop.WinHttp.WinHttpSetOption(requestHandle, Interop.WinHttp.WINHTTP_OPTION_REQUIRE_STREAM_END, ref optionData))
{
if (NetEventSource.Log.IsEnabled())
{
NetEventSource.Info(this, "Failed to enable WINHTTP_OPTION_REQUIRE_STREAM_END error code: " + Marshal.GetLastWin32Error());
}
}
}
}

private void SetWinHttpOption(SafeWinHttpHandle handle, uint option, ref uint optionData)
Expand Down