Merge branch 'release/2.1' into dev
This commit is contained in:
commit
809d7399c1
|
|
@ -8,7 +8,7 @@ environment:
|
|||
branches:
|
||||
only:
|
||||
- master
|
||||
- release
|
||||
- /release\/.*/
|
||||
- dev
|
||||
- /^(.*\/)?ci-.*$/
|
||||
build_script:
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@ addons:
|
|||
branches:
|
||||
only:
|
||||
- master
|
||||
- release
|
||||
- /release\/.*/
|
||||
- dev
|
||||
- /^(.*\/)?ci-.*$/
|
||||
install:
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@
|
|||
<MicrosoftNETCoreApp20PackageVersion>2.0.0</MicrosoftNETCoreApp20PackageVersion>
|
||||
<MicrosoftNETCoreApp21PackageVersion>2.1.0-preview1-26016-05</MicrosoftNETCoreApp21PackageVersion>
|
||||
<MicrosoftNETTestSdkPackageVersion>15.3.0</MicrosoftNETTestSdkPackageVersion>
|
||||
<SystemNumericsVectorsPackageVersion>4.5.0-preview1-26016-05</SystemNumericsVectorsPackageVersion>
|
||||
<SystemNetWebSocketsWebSocketProtocolPackageVersion>4.5.0-preview1-26119-06</SystemNetWebSocketsWebSocketProtocolPackageVersion>
|
||||
<XunitPackageVersion>2.3.1</XunitPackageVersion>
|
||||
<XunitRunnerVisualStudioPackageVersion>2.3.1</XunitRunnerVisualStudioPackageVersion>
|
||||
</PropertyGroup>
|
||||
|
|
|
|||
|
|
@ -1,44 +0,0 @@
|
|||
param([string]$CoreFxRepoRoot)
|
||||
|
||||
$RepoRoot = Split-Path -Parent $PSScriptRoot
|
||||
|
||||
$FilesToCopy = @(
|
||||
"src\Common\src\System\Net\WebSockets\ManagedWebSocket.cs",
|
||||
"src\Common\src\System\Net\WebSockets\WebSocketValidate.cs"
|
||||
)
|
||||
|
||||
if(!$CoreFxRepoRoot) {
|
||||
$CoreFxRepoRoot = "$RepoRoot\..\..\dotnet\corefx"
|
||||
}
|
||||
|
||||
if(!(Test-Path $CoreFxRepoRoot)) {
|
||||
throw "Could not find CoreFx repo at $CoreFxRepoRoot"
|
||||
}
|
||||
$CoreFxRepoRoot = Convert-Path $CoreFxRepoRoot
|
||||
|
||||
$DestinationRoot = "$RepoRoot\src\Microsoft.AspNetCore.WebSockets\Internal\fx"
|
||||
|
||||
$FilesToCopy | foreach {
|
||||
$Source = Join-Path $CoreFxRepoRoot $_
|
||||
$Destination = Join-Path $DestinationRoot $_
|
||||
$DestinationDir = Split-Path -Parent $Destination
|
||||
|
||||
if(!(Test-Path $Source)) {
|
||||
Write-Warning "Can't find source file: $Source"
|
||||
} else {
|
||||
if(!(Test-Path $DestinationDir)) {
|
||||
mkdir $DestinationDir | Out-Null
|
||||
}
|
||||
if(Test-Path $Destination) {
|
||||
del $Destination
|
||||
}
|
||||
Write-Host "Copying $_"
|
||||
|
||||
$SourceCode = [IO.File]::ReadAllText($Source)
|
||||
$SourceCode = $SourceCode.Replace("Task.FromException", "CompatHelpers.FromException")
|
||||
$SourceCode = $SourceCode.Replace("Task.CompletedTask", "CompatHelpers.CompletedTask")
|
||||
$SourceCode = $SourceCode.Replace("Array.Empty", "CompatHelpers.Empty")
|
||||
$SourceCode = $SourceCode.Replace("nameof(ClientWebSocket)", "`"ClientWebSocket`"")
|
||||
[IO.File]::WriteAllText($Destination, $SourceCode)
|
||||
}
|
||||
}
|
||||
|
|
@ -1,32 +0,0 @@
|
|||
// Copyright (c) .NET Foundation. All rights reserved.
|
||||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Net.WebSockets;
|
||||
|
||||
namespace Microsoft.AspNetCore.WebSockets.Internal
|
||||
{
|
||||
public static class WebSocketFactory
|
||||
{
|
||||
public static WebSocket CreateClientWebSocket(Stream stream, string subProtocol, TimeSpan keepAliveInterval, int receiveBufferSize)
|
||||
{
|
||||
return ManagedWebSocket.CreateFromConnectedStream(
|
||||
stream,
|
||||
isServer: false,
|
||||
subprotocol: subProtocol,
|
||||
keepAliveInterval: keepAliveInterval,
|
||||
receiveBufferSize: receiveBufferSize);
|
||||
}
|
||||
|
||||
public static WebSocket CreateServerWebSocket(Stream stream, string subProtocol, TimeSpan keepAliveInterval, int receiveBufferSize)
|
||||
{
|
||||
return ManagedWebSocket.CreateFromConnectedStream(
|
||||
stream,
|
||||
isServer: true,
|
||||
subprotocol: subProtocol,
|
||||
keepAliveInterval: keepAliveInterval,
|
||||
receiveBufferSize: receiveBufferSize);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,35 +0,0 @@
|
|||
using System.Threading.Tasks;
|
||||
|
||||
namespace System.Net.WebSockets
|
||||
{
|
||||
// Needed to support the WebSockets code from CoreFX.
|
||||
internal static class CompatHelpers
|
||||
{
|
||||
internal static readonly Task CompletedTask;
|
||||
|
||||
static CompatHelpers()
|
||||
{
|
||||
var tcs = new TaskCompletionSource<object>();
|
||||
tcs.SetResult(null);
|
||||
CompletedTask = tcs.Task;
|
||||
}
|
||||
|
||||
public static Task FromException(Exception ex)
|
||||
{
|
||||
return Task.FromException(ex);
|
||||
}
|
||||
|
||||
public static Task<T> FromException<T>(Exception ex)
|
||||
{
|
||||
return Task.FromException<T>(ex);
|
||||
}
|
||||
|
||||
internal static T[] Empty<T>()
|
||||
{
|
||||
return Array.Empty<T>();
|
||||
}
|
||||
}
|
||||
|
||||
// This is just here to be used by a nameof in the CoreFX code.
|
||||
//internal static class ClientWebSocket { }
|
||||
}
|
||||
|
|
@ -1,5 +0,0 @@
|
|||
# Code copied from dotnet/corefx
|
||||
|
||||
This is code copied out of dotnet/corefx. **Do not** modify anything under the `src` subdirectory as it is copied by `scripts\UpdateCoreFxCore.ps1` in this repo. The files in the root of this directory are only here to shim out code that the corefx code depends on.
|
||||
|
||||
Any changes to code under `src` in this directory MUST be made in dotnet/corefx as well and should mention `Tratcher`, `anurse` and `stephentoub`.
|
||||
|
|
@ -1,24 +0,0 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace System.Net.WebSockets
|
||||
{
|
||||
// Needed to support the WebSockets code from CoreFX.
|
||||
internal static class SR
|
||||
{
|
||||
internal static readonly string net_Websockets_AlreadyOneOutstandingOperation = nameof(net_Websockets_AlreadyOneOutstandingOperation);
|
||||
internal static readonly string net_WebSockets_Argument_InvalidMessageType = nameof(net_WebSockets_Argument_InvalidMessageType);
|
||||
internal static readonly string net_WebSockets_InvalidCharInProtocolString = nameof(net_WebSockets_InvalidCharInProtocolString);
|
||||
internal static readonly string net_WebSockets_InvalidCloseStatusCode = nameof(net_WebSockets_InvalidCloseStatusCode);
|
||||
internal static readonly string net_WebSockets_InvalidCloseStatusDescription = nameof(net_WebSockets_InvalidCloseStatusDescription);
|
||||
internal static readonly string net_WebSockets_InvalidEmptySubProtocol = nameof(net_WebSockets_InvalidEmptySubProtocol);
|
||||
internal static readonly string net_WebSockets_InvalidState = nameof(net_WebSockets_InvalidState);
|
||||
internal static readonly string net_WebSockets_InvalidState_ClosedOrAborted = nameof(net_WebSockets_InvalidState_ClosedOrAborted);
|
||||
internal static readonly string net_WebSockets_ReasonNotNull = nameof(net_WebSockets_ReasonNotNull);
|
||||
internal static readonly string net_WebSockets_UnsupportedPlatform = nameof(net_WebSockets_UnsupportedPlatform);
|
||||
|
||||
internal static string Format(string name, params object[] args) => $"TODO, RESX: {name}; ({string.Join(",", args)})";
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
|
|
@ -1,150 +0,0 @@
|
|||
// Licensed to the .NET Foundation under one or more agreements.
|
||||
// The .NET Foundation licenses this file to you under the MIT license.
|
||||
// See the LICENSE file in the project root for more information.
|
||||
|
||||
using System.Globalization;
|
||||
using System.Text;
|
||||
|
||||
namespace System.Net.WebSockets
|
||||
{
|
||||
internal static partial class WebSocketValidate
|
||||
{
|
||||
internal const int MaxControlFramePayloadLength = 123;
|
||||
private const int CloseStatusCodeAbort = 1006;
|
||||
private const int CloseStatusCodeFailedTLSHandshake = 1015;
|
||||
private const int InvalidCloseStatusCodesFrom = 0;
|
||||
private const int InvalidCloseStatusCodesTo = 999;
|
||||
private const string Separators = "()<>@,;:\\\"/[]?={} ";
|
||||
|
||||
internal static void ThrowIfInvalidState(WebSocketState currentState, bool isDisposed, WebSocketState[] validStates)
|
||||
{
|
||||
string validStatesText = string.Empty;
|
||||
|
||||
if (validStates != null && validStates.Length > 0)
|
||||
{
|
||||
foreach (WebSocketState validState in validStates)
|
||||
{
|
||||
if (currentState == validState)
|
||||
{
|
||||
// Ordering is important to maintain .NET 4.5 WebSocket implementation exception behavior.
|
||||
if (isDisposed)
|
||||
{
|
||||
throw new ObjectDisposedException("ClientWebSocket");
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
validStatesText = string.Join(", ", validStates);
|
||||
}
|
||||
|
||||
throw new WebSocketException(
|
||||
WebSocketError.InvalidState,
|
||||
SR.Format(SR.net_WebSockets_InvalidState, currentState, validStatesText));
|
||||
}
|
||||
|
||||
internal static void ValidateSubprotocol(string subProtocol)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(subProtocol))
|
||||
{
|
||||
throw new ArgumentException(SR.net_WebSockets_InvalidEmptySubProtocol, nameof(subProtocol));
|
||||
}
|
||||
|
||||
string invalidChar = null;
|
||||
int i = 0;
|
||||
while (i < subProtocol.Length)
|
||||
{
|
||||
char ch = subProtocol[i];
|
||||
if (ch < 0x21 || ch > 0x7e)
|
||||
{
|
||||
invalidChar = string.Format(CultureInfo.InvariantCulture, "[{0}]", (int)ch);
|
||||
break;
|
||||
}
|
||||
|
||||
if (!char.IsLetterOrDigit(ch) &&
|
||||
Separators.IndexOf(ch) >= 0)
|
||||
{
|
||||
invalidChar = ch.ToString();
|
||||
break;
|
||||
}
|
||||
|
||||
i++;
|
||||
}
|
||||
|
||||
if (invalidChar != null)
|
||||
{
|
||||
throw new ArgumentException(SR.Format(SR.net_WebSockets_InvalidCharInProtocolString, subProtocol, invalidChar), nameof(subProtocol));
|
||||
}
|
||||
}
|
||||
|
||||
internal static void ValidateCloseStatus(WebSocketCloseStatus closeStatus, string statusDescription)
|
||||
{
|
||||
if (closeStatus == WebSocketCloseStatus.Empty && !string.IsNullOrEmpty(statusDescription))
|
||||
{
|
||||
throw new ArgumentException(SR.Format(SR.net_WebSockets_ReasonNotNull,
|
||||
statusDescription,
|
||||
WebSocketCloseStatus.Empty),
|
||||
nameof(statusDescription));
|
||||
}
|
||||
|
||||
int closeStatusCode = (int)closeStatus;
|
||||
|
||||
if ((closeStatusCode >= InvalidCloseStatusCodesFrom &&
|
||||
closeStatusCode <= InvalidCloseStatusCodesTo) ||
|
||||
closeStatusCode == CloseStatusCodeAbort ||
|
||||
closeStatusCode == CloseStatusCodeFailedTLSHandshake)
|
||||
{
|
||||
// CloseStatus 1006 means Aborted - this will never appear on the wire and is reflected by calling WebSocket.Abort
|
||||
throw new ArgumentException(SR.Format(SR.net_WebSockets_InvalidCloseStatusCode,
|
||||
closeStatusCode),
|
||||
nameof(closeStatus));
|
||||
}
|
||||
|
||||
int length = 0;
|
||||
if (!string.IsNullOrEmpty(statusDescription))
|
||||
{
|
||||
length = Encoding.UTF8.GetByteCount(statusDescription);
|
||||
}
|
||||
|
||||
if (length > MaxControlFramePayloadLength)
|
||||
{
|
||||
throw new ArgumentException(SR.Format(SR.net_WebSockets_InvalidCloseStatusDescription,
|
||||
statusDescription,
|
||||
MaxControlFramePayloadLength),
|
||||
nameof(statusDescription));
|
||||
}
|
||||
}
|
||||
|
||||
internal static void ThrowPlatformNotSupportedException()
|
||||
{
|
||||
throw new PlatformNotSupportedException(SR.net_WebSockets_UnsupportedPlatform);
|
||||
}
|
||||
|
||||
internal static void ValidateArraySegment(ArraySegment<byte> arraySegment, string parameterName)
|
||||
{
|
||||
if (arraySegment.Array == null)
|
||||
{
|
||||
throw new ArgumentNullException(parameterName + ".Array");
|
||||
}
|
||||
}
|
||||
|
||||
internal static void ValidateBuffer(byte[] buffer, int offset, int count)
|
||||
{
|
||||
if (buffer == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(buffer));
|
||||
}
|
||||
|
||||
if (offset < 0 || offset > buffer.Length)
|
||||
{
|
||||
throw new ArgumentOutOfRangeException(nameof(offset));
|
||||
}
|
||||
|
||||
if (count < 0 || count > (buffer.Length - offset))
|
||||
{
|
||||
throw new ArgumentOutOfRangeException(nameof(count));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -12,7 +12,7 @@
|
|||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.AspNetCore.Http.Extensions" Version="$(MicrosoftAspNetCoreHttpExtensionsPackageVersion)" />
|
||||
<PackageReference Include="Microsoft.Extensions.Options" Version="$(MicrosoftExtensionsOptionsPackageVersion)" />
|
||||
<PackageReference Include="System.Numerics.Vectors" Version="$(SystemNumericsVectorsPackageVersion)" />
|
||||
<PackageReference Include="System.Net.WebSockets.WebSocketProtocol" Version="$(SystemNetWebSocketsWebSocketProtocolPackageVersion)" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
|
|
|||
|
|
@ -118,7 +118,7 @@ namespace Microsoft.AspNetCore.WebSockets
|
|||
}
|
||||
Stream opaqueTransport = await _upgradeFeature.UpgradeAsync(); // Sets status code to 101
|
||||
|
||||
return WebSocketFactory.CreateServerWebSocket(opaqueTransport, subProtocol, keepAliveInterval, receiveBufferSize);
|
||||
return WebSocketProtocol.CreateFromStream(opaqueTransport, isServer: true, subProtocol: subProtocol, keepAliveInterval: keepAliveInterval);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
using System;
|
||||
using System;
|
||||
using System.Net.WebSockets;
|
||||
using Microsoft.AspNetCore.WebSockets.Internal;
|
||||
|
||||
|
|
@ -28,8 +28,8 @@ namespace Microsoft.AspNetCore.WebSockets.Test
|
|||
return new WebSocketPair(
|
||||
serverStream,
|
||||
clientStream,
|
||||
clientSocket: WebSocketFactory.CreateClientWebSocket(clientStream, null, TimeSpan.FromMinutes(2), 1024),
|
||||
serverSocket: WebSocketFactory.CreateServerWebSocket(serverStream, null, TimeSpan.FromMinutes(2), 1024));
|
||||
clientSocket: WebSocketProtocol.CreateFromStream(clientStream, isServer: false, subProtocol: null, keepAliveInterval: TimeSpan.FromMinutes(2)),
|
||||
serverSocket: WebSocketProtocol.CreateFromStream(serverStream, isServer: true, subProtocol: null, keepAliveInterval: TimeSpan.FromMinutes(2)));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue