Skip to content

Commit

Permalink
Rename HttpVersion and HttpVersionPolicy
Browse files Browse the repository at this point in the history
  • Loading branch information
Katya Sokolova committed Jun 20, 2022
1 parent 08d1f8c commit 71cc887
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,10 @@ internal ClientWebSocketOptions() { }
public System.Net.Security.RemoteCertificateValidationCallback? RemoteCertificateValidationCallback { get { throw null; } set { } }
[System.Runtime.Versioning.UnsupportedOSPlatformAttribute("browser")]
public bool UseDefaultCredentials { get { throw null; } set { } }
public System.Version Version { get { throw null; }
public System.Version HttpVersion { get { throw null; }
[System.Runtime.Versioning.UnsupportedOSPlatformAttribute("browser")]
set { } }
public System.Net.Http.HttpVersionPolicy VersionPolicy { get { throw null; }
public System.Net.Http.HttpVersionPolicy HttpVersionPolicy { get { throw null; }
[System.Runtime.Versioning.UnsupportedOSPlatformAttribute("browser")]
set { } }
public void AddSubProtocol(string subProtocol) { }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public sealed class ClientWebSocketOptions
{
private bool _isReadOnly; // After ConnectAsync is called the options cannot be modified.
private List<string>? _requestedSubProtocols;
private Version _version = HttpVersion.Version11;
private Version _version = Net.HttpVersion.Version11;
private HttpVersionPolicy _versionPolicy = HttpVersionPolicy.RequestVersionOrLower;

internal ClientWebSocketOptions()
Expand All @@ -35,14 +35,14 @@ public bool UseDefaultCredentials
set => throw new PlatformNotSupportedException();
}

public Version Version
public Version HttpVersion
{
get => _version;
[UnsupportedOSPlatform("browser")]
set => throw new PlatformNotSupportedException();
}

public System.Net.Http.HttpVersionPolicy VersionPolicy
public System.Net.Http.HttpVersionPolicy HttpVersionPolicy
{
get => _versionPolicy;
[UnsupportedOSPlatform("browser")]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ public sealed class ClientWebSocketOptions
internal X509CertificateCollection? _clientCertificates;
internal WebHeaderCollection? _requestHeaders;
internal List<string>? _requestedSubProtocols;
private Version _version = HttpVersion.Version11;
private Version _version = Net.HttpVersion.Version11;
private HttpVersionPolicy _versionPolicy = HttpVersionPolicy.RequestVersionOrLower;

public Version Version
public Version HttpVersion
{
get => _version;
[UnsupportedOSPlatform("browser")]
Expand All @@ -40,7 +40,7 @@ public Version Version
}
}

public HttpVersionPolicy VersionPolicy
public HttpVersionPolicy HttpVersionPolicy
{
get => _versionPolicy;
[UnsupportedOSPlatform("browser")]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,13 @@ public async Task ConnectAsync(Uri uri, HttpMessageInvoker? handler, Cancellatio
bool disposeHandler = true;
try
{
if (options.Version.Major >= 3 && options.VersionPolicy != HttpVersionPolicy.RequestVersionOrLower)
if (options.HttpVersion.Major >= 3 && options.HttpVersionPolicy != HttpVersionPolicy.RequestVersionOrLower)
{
throw new Exception();
}

var request = new HttpRequestMessage(HttpMethod.Get, uri);
if (options.Version.Major >= 2 || (options.VersionPolicy == HttpVersionPolicy.RequestVersionOrHigher))
if (options.HttpVersion.Major >= 2 || (options.HttpVersionPolicy == HttpVersionPolicy.RequestVersionOrHigher))
{
request.Version = new Version(2, 0);
}
Expand Down Expand Up @@ -108,8 +108,8 @@ public async Task ConnectAsync(Uri uri, HttpMessageInvoker? handler, Cancellatio
catch (HttpRequestException ex)
{
if (ex.Data.Contains("SETTINGS_ENABLE_CONNECT_PROTOCOL") && request.Version.Major == 2
&& (options.Version.Major == 2 && options.VersionPolicy == HttpVersionPolicy.RequestVersionOrLower
|| options.Version.Major == 1 && options.VersionPolicy == HttpVersionPolicy.RequestVersionOrHigher))
&& (options.HttpVersion.Major == 2 && options.HttpVersionPolicy == HttpVersionPolicy.RequestVersionOrLower
|| options.HttpVersion.Major == 1 && options.HttpVersionPolicy == HttpVersionPolicy.RequestVersionOrHigher))
{
request.Version = new Version(1, 1);
}
Expand Down Expand Up @@ -343,17 +343,17 @@ static int ParseWindowBits(ReadOnlySpan<char> value)
/// <param name="options">The options controlling the request.</param>
private static void AddWebSocketHeaders(HttpRequestMessage request, string secKey, ClientWebSocketOptions options)
{
request.Version = options.Version;
request.Version = options.HttpVersion;
// always exact because we handle downgrade here
request.VersionPolicy = HttpVersionPolicy.RequestVersionExact;

if (options.Version == HttpVersion.Version11)
if (options.HttpVersion == HttpVersion.Version11)
{
request.Headers.TryAddWithoutValidation(HttpKnownHeaderNames.Connection, HttpKnownHeaderNames.Upgrade);
request.Headers.TryAddWithoutValidation(HttpKnownHeaderNames.Upgrade, "websocket");
request.Headers.TryAddWithoutValidation(HttpKnownHeaderNames.SecWebSocketKey, secKey);
}
else if (options.Version == HttpVersion.Version20)
else if (options.HttpVersion == HttpVersion.Version20)
{
request.Method = HttpMethod.Connect;
request.Headers.Protocol = "websocket";
Expand Down Expand Up @@ -408,7 +408,7 @@ static string GetDeflateOptions(WebSocketDeflateOptions options)

private static void ValidateResponse(HttpResponseMessage response, string secValue, ClientWebSocketOptions options)
{
if (options.Version == HttpVersion.Version11)
if (options.HttpVersion == HttpVersion.Version11)
{
if (response.StatusCode != HttpStatusCode.SwitchingProtocols)
{
Expand All @@ -420,7 +420,7 @@ private static void ValidateResponse(HttpResponseMessage response, string secVal
ValidateHeader(response.Headers, HttpKnownHeaderNames.Upgrade, "websocket");
ValidateHeader(response.Headers, HttpKnownHeaderNames.SecWebSocketAccept, secValue);
}
else if (options.Version == HttpVersion.Version20)
else if (options.HttpVersion == HttpVersion.Version20)
{
if (response.StatusCode != HttpStatusCode.OK)
{
Expand Down

0 comments on commit 71cc887

Please sign in to comment.