Skip to content

Commit

Permalink
Merge Pull Requests from Original Repository
Browse files Browse the repository at this point in the history
sta#22 - Added CustomHeaders to WebSocketClient (Enhancement)
sta#198 - Wildcard Regex pattern for Service Paths
sta#730 - add_http_response_code_and_body_when_handshake_error
  • Loading branch information
Willis1776 committed Jan 31, 2024
1 parent 35e255e commit 06eb723
Show file tree
Hide file tree
Showing 13 changed files with 186 additions and 83 deletions.
10 changes: 10 additions & 0 deletions .vs/websocket-sharp/ColorByRegexConfig.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// This file contains rules to color document tabs by regular expressions. Each line contains a regular expression that will be tested against a file's full path. All files matching a regular expression will share a color.
// You can customize the color assigned to any group of files by right-clicking the tab and choosing "Set Tab Color."
// Regular expressions will be matched in the order they appear in this file. See https://docs.microsoft.com/en-us/dotnet/standard/base-types/regular-expressions for syntax.
// Regular expressions are matched as case-insensitive by default. You can override this behavior using capture group options like "(?-i:expression)".
// Edit this file and save your changes to see changes immediately applied. Any errors encountered during parsing or evaluating expressions will appear in the Output Window in a pane named "Color by Regular Expression."
^.*\.cs$
^.*\.fs$
^.*\.vb$
^.*\.cp?p?$
^.*\.hp?p?$
Binary file not shown.
7 changes: 6 additions & 1 deletion Example/Example.csproj
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="3.5" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Project DefaultTargets="Build" ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
Expand All @@ -10,6 +10,11 @@
<RootNamespace>Example</RootNamespace>
<AssemblyName>example</AssemblyName>
<TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
<FileUpgradeFlags>
</FileUpgradeFlags>
<UpgradeBackupLocation>
</UpgradeBackupLocation>
<OldToolsVersion>3.5</OldToolsVersion>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
Expand Down
7 changes: 6 additions & 1 deletion Example2/Example2.csproj
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="3.5" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Project DefaultTargets="Build" ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
Expand All @@ -10,6 +10,11 @@
<RootNamespace>Example2</RootNamespace>
<AssemblyName>example2</AssemblyName>
<TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
<FileUpgradeFlags>
</FileUpgradeFlags>
<UpgradeBackupLocation>
</UpgradeBackupLocation>
<OldToolsVersion>3.5</OldToolsVersion>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
Expand Down
7 changes: 6 additions & 1 deletion Example3/Example3.csproj
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="3.5" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Project DefaultTargets="Build" ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
Expand All @@ -10,6 +10,11 @@
<RootNamespace>Example3</RootNamespace>
<AssemblyName>example3</AssemblyName>
<TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
<FileUpgradeFlags>
</FileUpgradeFlags>
<UpgradeBackupLocation>
</UpgradeBackupLocation>
<OldToolsVersion>3.5</OldToolsVersion>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
Expand Down
32 changes: 20 additions & 12 deletions websocket-sharp.sln
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@

Microsoft Visual Studio Solution File, Format Version 10.00
# Visual Studio 2008
Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.8.34330.188
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "websocket-sharp", "websocket-sharp\websocket-sharp.csproj", "{B357BAC7-529E-4D81-A0D2-71041B19C8DE}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Example", "Example\Example.csproj", "{52805AEC-EFB1-4F42-BB8E-3ED4E692C568}"
Expand All @@ -11,20 +13,12 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Example3", "Example3\Exampl
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
Debug_Ubuntu|Any CPU = Debug_Ubuntu|Any CPU
Debug|Any CPU = Debug|Any CPU
Release_Ubuntu|Any CPU = Release_Ubuntu|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{52805AEC-EFB1-4F42-BB8E-3ED4E692C568}.Debug_Ubuntu|Any CPU.ActiveCfg = Debug_Ubuntu|Any CPU
{52805AEC-EFB1-4F42-BB8E-3ED4E692C568}.Debug_Ubuntu|Any CPU.Build.0 = Debug_Ubuntu|Any CPU
{52805AEC-EFB1-4F42-BB8E-3ED4E692C568}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{52805AEC-EFB1-4F42-BB8E-3ED4E692C568}.Debug|Any CPU.Build.0 = Debug|Any CPU
{52805AEC-EFB1-4F42-BB8E-3ED4E692C568}.Release_Ubuntu|Any CPU.ActiveCfg = Release_Ubuntu|Any CPU
{52805AEC-EFB1-4F42-BB8E-3ED4E692C568}.Release_Ubuntu|Any CPU.Build.0 = Release_Ubuntu|Any CPU
{52805AEC-EFB1-4F42-BB8E-3ED4E692C568}.Release|Any CPU.ActiveCfg = Release|Any CPU
{52805AEC-EFB1-4F42-BB8E-3ED4E692C568}.Release|Any CPU.Build.0 = Release|Any CPU
{B357BAC7-529E-4D81-A0D2-71041B19C8DE}.Debug_Ubuntu|Any CPU.ActiveCfg = Debug_Ubuntu|Any CPU
{B357BAC7-529E-4D81-A0D2-71041B19C8DE}.Debug_Ubuntu|Any CPU.Build.0 = Debug_Ubuntu|Any CPU
{B357BAC7-529E-4D81-A0D2-71041B19C8DE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
Expand All @@ -33,6 +27,14 @@ Global
{B357BAC7-529E-4D81-A0D2-71041B19C8DE}.Release_Ubuntu|Any CPU.Build.0 = Release_Ubuntu|Any CPU
{B357BAC7-529E-4D81-A0D2-71041B19C8DE}.Release|Any CPU.ActiveCfg = Release|Any CPU
{B357BAC7-529E-4D81-A0D2-71041B19C8DE}.Release|Any CPU.Build.0 = Release|Any CPU
{52805AEC-EFB1-4F42-BB8E-3ED4E692C568}.Debug_Ubuntu|Any CPU.ActiveCfg = Debug_Ubuntu|Any CPU
{52805AEC-EFB1-4F42-BB8E-3ED4E692C568}.Debug_Ubuntu|Any CPU.Build.0 = Debug_Ubuntu|Any CPU
{52805AEC-EFB1-4F42-BB8E-3ED4E692C568}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{52805AEC-EFB1-4F42-BB8E-3ED4E692C568}.Debug|Any CPU.Build.0 = Debug|Any CPU
{52805AEC-EFB1-4F42-BB8E-3ED4E692C568}.Release_Ubuntu|Any CPU.ActiveCfg = Release_Ubuntu|Any CPU
{52805AEC-EFB1-4F42-BB8E-3ED4E692C568}.Release_Ubuntu|Any CPU.Build.0 = Release_Ubuntu|Any CPU
{52805AEC-EFB1-4F42-BB8E-3ED4E692C568}.Release|Any CPU.ActiveCfg = Release|Any CPU
{52805AEC-EFB1-4F42-BB8E-3ED4E692C568}.Release|Any CPU.Build.0 = Release|Any CPU
{B81A24C8-25BB-42B2-AF99-1E1EACCE74C7}.Debug_Ubuntu|Any CPU.ActiveCfg = Debug_Ubuntu|Any CPU
{B81A24C8-25BB-42B2-AF99-1E1EACCE74C7}.Debug_Ubuntu|Any CPU.Build.0 = Debug_Ubuntu|Any CPU
{B81A24C8-25BB-42B2-AF99-1E1EACCE74C7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
Expand All @@ -50,6 +52,12 @@ Global
{C648BA25-77E5-4A40-A97F-D0AA37B9FB26}.Release|Any CPU.ActiveCfg = Release|Any CPU
{C648BA25-77E5-4A40-A97F-D0AA37B9FB26}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {B3E526A7-E073-493C-BF29-F31CB108DBBF}
EndGlobalSection
GlobalSection(MonoDevelopProperties) = preSolution
StartupItem = websocket-sharp\websocket-sharp.csproj
Policies = $0
Expand Down
22 changes: 22 additions & 0 deletions websocket-sharp/CloseEventArgs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,28 @@ public string Reason {
}
}

/// <summary>
/// Gets the http status code for the handshake error
/// </summary>
/// <value>
/// <para>
/// A <see cref="int"/> that represents http status code for
/// the handshake error
/// </para>
/// </value>
public int HttpStatusCode => _payloadData.HttpStatusCode;

/// <summary>
/// Gets the http response body for the handshake error
/// </summary>
/// <value>
/// <para>
/// A <see cref="int"/> that represents http response body for
/// the handshake error
/// </para>
/// </value>
public string HttpResponseBody => _payloadData.HttpResponseBody;

/// <summary>
/// Gets a value indicating whether the connection has been closed cleanly.
/// </summary>
Expand Down
77 changes: 31 additions & 46 deletions websocket-sharp/PayloadData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ internal class PayloadData : IEnumerable<byte>
#region Private Fields

private byte[] _data;
private long _extDataLength;
private long _length;

#endregion
Expand Down Expand Up @@ -72,7 +71,7 @@ internal class PayloadData : IEnumerable<byte>
static PayloadData ()
{
Empty = new PayloadData (WebSocket.EmptyBytes, 0);
MaxLength = Int64.MaxValue;
MaxLength = long.MaxValue;
}

#endregion
Expand All @@ -96,74 +95,60 @@ internal PayloadData (ushort code, string reason)
_length = _data.LongLength;
}

internal PayloadData(ushort code, string reason, int httpStatusCode, string httpResponseBody)
{
_data = code.Append(reason);
_length = _data.LongLength;
HttpStatusCode = httpStatusCode;
HttpResponseBody = httpResponseBody;

}

#endregion

#region Internal Properties

internal ushort Code {
get {
return _length >= 2
? _data.SubArray (0, 2).ToUInt16 (ByteOrder.Big)
: (ushort) 1005;
}
}
internal int HttpStatusCode { get; }

internal long ExtensionDataLength {
get {
return _extDataLength;
}
internal string HttpResponseBody { get; }

set {
_extDataLength = value;
}
}
internal ushort Code =>
_length >= 2
? _data.SubArray (0, 2).ToUInt16 (ByteOrder.Big)
: (ushort) 1005;

internal bool HasReservedCode {
get {
return _length >= 2 && Code.IsReservedStatusCode ();
}
}
internal long ExtensionDataLength { get; set; }

internal bool HasReservedCode => _length >= 2 && Code.IsReservedStatusCode ();

internal string Reason {
get {
if (_length <= 2)
return String.Empty;
return string.Empty;

var bytes = _data.SubArray (2, _length - 2);

string reason;

return bytes.TryGetUTF8DecodedString (out reason)
return bytes.TryGetUTF8DecodedString (out var reason)
? reason
: String.Empty;
: string.Empty;
}
}

#endregion

#region Public Properties

public byte[] ApplicationData {
get {
return _extDataLength > 0
? _data.SubArray (_extDataLength, _length - _extDataLength)
: _data;
}
}
public byte[] ApplicationData =>
ExtensionDataLength > 0
? _data.SubArray (ExtensionDataLength, _length - ExtensionDataLength)
: _data;

public byte[] ExtensionData {
get {
return _extDataLength > 0
? _data.SubArray (0, _extDataLength)
: WebSocket.EmptyBytes;
}
}
public byte[] ExtensionData =>
ExtensionDataLength > 0
? _data.SubArray (0, ExtensionDataLength)
: WebSocket.EmptyBytes;

public ulong Length {
get {
return (ulong) _length;
}
}
public ulong Length => (ulong) _length;

#endregion

Expand Down
4 changes: 2 additions & 2 deletions websocket-sharp/Server/HttpServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -830,7 +830,7 @@ private static HttpListener createListener (
}

private void init (
string hostname, System.Net.IPAddress address, int port, bool secure
string hostname, System.Net.IPAddress address, int port, bool secure, bool wildcardServicesPath = false
)
{
_hostname = hostname;
Expand All @@ -841,7 +841,7 @@ private void init (
_docRootPath = "./Public";
_listener = createListener (_hostname, _port, _secure);
_log = _listener.Log;
_services = new WebSocketServiceManager (_log);
_services = new WebSocketServiceManager (_log, wildcardServicesPath);
_sync = new object ();
}

Expand Down
Loading

0 comments on commit 06eb723

Please sign in to comment.