Skip to content
Closed
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ internal static partial class WinHttp
public const uint WINHTTP_PROTOCOL_FLAG_HTTP3 = 0x2;
public const uint WINHTTP_HTTP2_PLUS_CLIENT_CERT_FLAG = 0x1;
public const uint WINHTTP_OPTION_DISABLE_STREAM_QUEUE = 139;
public const uint WINHTTP_OPTION_HTTP_PROTOCOL_REQUIRED = 145;

public const uint WINHTTP_OPTION_UPGRADE_TO_WEB_SOCKET = 114;
public const uint WINHTTP_OPTION_WEB_SOCKET_CLOSE_TIMEOUT = 115;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -903,17 +903,7 @@ private async Task StartRequestAsync(WinHttpRequestState state)
ThrowOnInvalidHandle(connectHandle, nameof(Interop.WinHttp.WinHttpConnect));
connectHandle.SetParentHandle(_sessionHandle);

// Try to use the requested version if a known/supported version was explicitly requested.
// Otherwise, we simply use winhttp's default.
string? httpVersion = null;
if (state.RequestMessage.Version == HttpVersion.Version10)
{
httpVersion = "HTTP/1.0";
}
else if (state.RequestMessage.Version == HttpVersion.Version11)
{
httpVersion = "HTTP/1.1";
}
string httpVersion = $"HTTP/{state.RequestMessage.Version.Major}.{state.RequestMessage.Version.Minor}";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

note that this change causes a (minor) allocation of the string per each request.

Copy link
Member

@liveans liveans Jan 27, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for reminding this! This PR contains some experiments for the CI machines atm, will get back to this once my plate is not full anymore


OpenRequestHandle(state, connectHandle, httpVersion, out WinHttpChunkMode chunkedModeForSend, out SafeWinHttpHandle requestHandle);
state.RequestHandle = requestHandle;
Expand Down Expand Up @@ -1552,6 +1542,15 @@ private void SetRequestHandleHttpProtocolOptions(SafeWinHttpHandle requestHandle
{
if (NetEventSource.Log.IsEnabled()) NetEventSource.Info(this, $"HTTP/{requestVersion.Major} option not supported");
}

uint protocolRequired = 1;
if (optionData != 0 && !Interop.WinHttp.WinHttpSetOption(
requestHandle,
Interop.WinHttp.WINHTTP_OPTION_HTTP_PROTOCOL_REQUIRED,
ref protocolRequired))
{
if (NetEventSource.Log.IsEnabled()) NetEventSource.Info(this, "HTTP protocol required option not supported");
}
}

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