Skip to content

Commit 06eb723

Browse files
committed
Merge Pull Requests from Original Repository
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
1 parent 35e255e commit 06eb723

13 files changed

+186
-83
lines changed
+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// 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.
2+
// You can customize the color assigned to any group of files by right-clicking the tab and choosing "Set Tab Color."
3+
// 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.
4+
// Regular expressions are matched as case-insensitive by default. You can override this behavior using capture group options like "(?-i:expression)".
5+
// 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."
6+
^.*\.cs$
7+
^.*\.fs$
8+
^.*\.vb$
9+
^.*\.cp?p?$
10+
^.*\.hp?p?$
Binary file not shown.

Example/Example.csproj

+6-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?xml version="1.0" encoding="utf-8"?>
2-
<Project DefaultTargets="Build" ToolsVersion="3.5" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
2+
<Project DefaultTargets="Build" ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
33
<PropertyGroup>
44
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
55
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
@@ -10,6 +10,11 @@
1010
<RootNamespace>Example</RootNamespace>
1111
<AssemblyName>example</AssemblyName>
1212
<TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
13+
<FileUpgradeFlags>
14+
</FileUpgradeFlags>
15+
<UpgradeBackupLocation>
16+
</UpgradeBackupLocation>
17+
<OldToolsVersion>3.5</OldToolsVersion>
1318
</PropertyGroup>
1419
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
1520
<DebugSymbols>true</DebugSymbols>

Example2/Example2.csproj

+6-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?xml version="1.0" encoding="utf-8"?>
2-
<Project DefaultTargets="Build" ToolsVersion="3.5" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
2+
<Project DefaultTargets="Build" ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
33
<PropertyGroup>
44
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
55
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
@@ -10,6 +10,11 @@
1010
<RootNamespace>Example2</RootNamespace>
1111
<AssemblyName>example2</AssemblyName>
1212
<TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
13+
<FileUpgradeFlags>
14+
</FileUpgradeFlags>
15+
<UpgradeBackupLocation>
16+
</UpgradeBackupLocation>
17+
<OldToolsVersion>3.5</OldToolsVersion>
1318
</PropertyGroup>
1419
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
1520
<DebugSymbols>true</DebugSymbols>

Example3/Example3.csproj

+6-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?xml version="1.0" encoding="utf-8"?>
2-
<Project DefaultTargets="Build" ToolsVersion="3.5" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
2+
<Project DefaultTargets="Build" ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
33
<PropertyGroup>
44
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
55
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
@@ -10,6 +10,11 @@
1010
<RootNamespace>Example3</RootNamespace>
1111
<AssemblyName>example3</AssemblyName>
1212
<TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
13+
<FileUpgradeFlags>
14+
</FileUpgradeFlags>
15+
<UpgradeBackupLocation>
16+
</UpgradeBackupLocation>
17+
<OldToolsVersion>3.5</OldToolsVersion>
1318
</PropertyGroup>
1419
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
1520
<DebugSymbols>true</DebugSymbols>

websocket-sharp.sln

+20-12
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11

2-
Microsoft Visual Studio Solution File, Format Version 10.00
3-
# Visual Studio 2008
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio Version 17
4+
VisualStudioVersion = 17.8.34330.188
5+
MinimumVisualStudioVersion = 10.0.40219.1
46
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "websocket-sharp", "websocket-sharp\websocket-sharp.csproj", "{B357BAC7-529E-4D81-A0D2-71041B19C8DE}"
57
EndProject
68
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Example", "Example\Example.csproj", "{52805AEC-EFB1-4F42-BB8E-3ED4E692C568}"
@@ -11,20 +13,12 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Example3", "Example3\Exampl
1113
EndProject
1214
Global
1315
GlobalSection(SolutionConfigurationPlatforms) = preSolution
14-
Debug|Any CPU = Debug|Any CPU
15-
Release|Any CPU = Release|Any CPU
1616
Debug_Ubuntu|Any CPU = Debug_Ubuntu|Any CPU
17+
Debug|Any CPU = Debug|Any CPU
1718
Release_Ubuntu|Any CPU = Release_Ubuntu|Any CPU
19+
Release|Any CPU = Release|Any CPU
1820
EndGlobalSection
1921
GlobalSection(ProjectConfigurationPlatforms) = postSolution
20-
{52805AEC-EFB1-4F42-BB8E-3ED4E692C568}.Debug_Ubuntu|Any CPU.ActiveCfg = Debug_Ubuntu|Any CPU
21-
{52805AEC-EFB1-4F42-BB8E-3ED4E692C568}.Debug_Ubuntu|Any CPU.Build.0 = Debug_Ubuntu|Any CPU
22-
{52805AEC-EFB1-4F42-BB8E-3ED4E692C568}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
23-
{52805AEC-EFB1-4F42-BB8E-3ED4E692C568}.Debug|Any CPU.Build.0 = Debug|Any CPU
24-
{52805AEC-EFB1-4F42-BB8E-3ED4E692C568}.Release_Ubuntu|Any CPU.ActiveCfg = Release_Ubuntu|Any CPU
25-
{52805AEC-EFB1-4F42-BB8E-3ED4E692C568}.Release_Ubuntu|Any CPU.Build.0 = Release_Ubuntu|Any CPU
26-
{52805AEC-EFB1-4F42-BB8E-3ED4E692C568}.Release|Any CPU.ActiveCfg = Release|Any CPU
27-
{52805AEC-EFB1-4F42-BB8E-3ED4E692C568}.Release|Any CPU.Build.0 = Release|Any CPU
2822
{B357BAC7-529E-4D81-A0D2-71041B19C8DE}.Debug_Ubuntu|Any CPU.ActiveCfg = Debug_Ubuntu|Any CPU
2923
{B357BAC7-529E-4D81-A0D2-71041B19C8DE}.Debug_Ubuntu|Any CPU.Build.0 = Debug_Ubuntu|Any CPU
3024
{B357BAC7-529E-4D81-A0D2-71041B19C8DE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
@@ -33,6 +27,14 @@ Global
3327
{B357BAC7-529E-4D81-A0D2-71041B19C8DE}.Release_Ubuntu|Any CPU.Build.0 = Release_Ubuntu|Any CPU
3428
{B357BAC7-529E-4D81-A0D2-71041B19C8DE}.Release|Any CPU.ActiveCfg = Release|Any CPU
3529
{B357BAC7-529E-4D81-A0D2-71041B19C8DE}.Release|Any CPU.Build.0 = Release|Any CPU
30+
{52805AEC-EFB1-4F42-BB8E-3ED4E692C568}.Debug_Ubuntu|Any CPU.ActiveCfg = Debug_Ubuntu|Any CPU
31+
{52805AEC-EFB1-4F42-BB8E-3ED4E692C568}.Debug_Ubuntu|Any CPU.Build.0 = Debug_Ubuntu|Any CPU
32+
{52805AEC-EFB1-4F42-BB8E-3ED4E692C568}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
33+
{52805AEC-EFB1-4F42-BB8E-3ED4E692C568}.Debug|Any CPU.Build.0 = Debug|Any CPU
34+
{52805AEC-EFB1-4F42-BB8E-3ED4E692C568}.Release_Ubuntu|Any CPU.ActiveCfg = Release_Ubuntu|Any CPU
35+
{52805AEC-EFB1-4F42-BB8E-3ED4E692C568}.Release_Ubuntu|Any CPU.Build.0 = Release_Ubuntu|Any CPU
36+
{52805AEC-EFB1-4F42-BB8E-3ED4E692C568}.Release|Any CPU.ActiveCfg = Release|Any CPU
37+
{52805AEC-EFB1-4F42-BB8E-3ED4E692C568}.Release|Any CPU.Build.0 = Release|Any CPU
3638
{B81A24C8-25BB-42B2-AF99-1E1EACCE74C7}.Debug_Ubuntu|Any CPU.ActiveCfg = Debug_Ubuntu|Any CPU
3739
{B81A24C8-25BB-42B2-AF99-1E1EACCE74C7}.Debug_Ubuntu|Any CPU.Build.0 = Debug_Ubuntu|Any CPU
3840
{B81A24C8-25BB-42B2-AF99-1E1EACCE74C7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
@@ -50,6 +52,12 @@ Global
5052
{C648BA25-77E5-4A40-A97F-D0AA37B9FB26}.Release|Any CPU.ActiveCfg = Release|Any CPU
5153
{C648BA25-77E5-4A40-A97F-D0AA37B9FB26}.Release|Any CPU.Build.0 = Release|Any CPU
5254
EndGlobalSection
55+
GlobalSection(SolutionProperties) = preSolution
56+
HideSolutionNode = FALSE
57+
EndGlobalSection
58+
GlobalSection(ExtensibilityGlobals) = postSolution
59+
SolutionGuid = {B3E526A7-E073-493C-BF29-F31CB108DBBF}
60+
EndGlobalSection
5361
GlobalSection(MonoDevelopProperties) = preSolution
5462
StartupItem = websocket-sharp\websocket-sharp.csproj
5563
Policies = $0

websocket-sharp/CloseEventArgs.cs

+22
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,28 @@ public string Reason {
100100
}
101101
}
102102

103+
/// <summary>
104+
/// Gets the http status code for the handshake error
105+
/// </summary>
106+
/// <value>
107+
/// <para>
108+
/// A <see cref="int"/> that represents http status code for
109+
/// the handshake error
110+
/// </para>
111+
/// </value>
112+
public int HttpStatusCode => _payloadData.HttpStatusCode;
113+
114+
/// <summary>
115+
/// Gets the http response body for the handshake error
116+
/// </summary>
117+
/// <value>
118+
/// <para>
119+
/// A <see cref="int"/> that represents http response body for
120+
/// the handshake error
121+
/// </para>
122+
/// </value>
123+
public string HttpResponseBody => _payloadData.HttpResponseBody;
124+
103125
/// <summary>
104126
/// Gets a value indicating whether the connection has been closed cleanly.
105127
/// </summary>

websocket-sharp/PayloadData.cs

+31-46
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ internal class PayloadData : IEnumerable<byte>
3737
#region Private Fields
3838

3939
private byte[] _data;
40-
private long _extDataLength;
4140
private long _length;
4241

4342
#endregion
@@ -72,7 +71,7 @@ internal class PayloadData : IEnumerable<byte>
7271
static PayloadData ()
7372
{
7473
Empty = new PayloadData (WebSocket.EmptyBytes, 0);
75-
MaxLength = Int64.MaxValue;
74+
MaxLength = long.MaxValue;
7675
}
7776

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

98+
internal PayloadData(ushort code, string reason, int httpStatusCode, string httpResponseBody)
99+
{
100+
_data = code.Append(reason);
101+
_length = _data.LongLength;
102+
HttpStatusCode = httpStatusCode;
103+
HttpResponseBody = httpResponseBody;
104+
105+
}
106+
99107
#endregion
100108

101109
#region Internal Properties
102110

103-
internal ushort Code {
104-
get {
105-
return _length >= 2
106-
? _data.SubArray (0, 2).ToUInt16 (ByteOrder.Big)
107-
: (ushort) 1005;
108-
}
109-
}
111+
internal int HttpStatusCode { get; }
110112

111-
internal long ExtensionDataLength {
112-
get {
113-
return _extDataLength;
114-
}
113+
internal string HttpResponseBody { get; }
115114

116-
set {
117-
_extDataLength = value;
118-
}
119-
}
115+
internal ushort Code =>
116+
_length >= 2
117+
? _data.SubArray (0, 2).ToUInt16 (ByteOrder.Big)
118+
: (ushort) 1005;
120119

121-
internal bool HasReservedCode {
122-
get {
123-
return _length >= 2 && Code.IsReservedStatusCode ();
124-
}
125-
}
120+
internal long ExtensionDataLength { get; set; }
121+
122+
internal bool HasReservedCode => _length >= 2 && Code.IsReservedStatusCode ();
126123

127124
internal string Reason {
128125
get {
129126
if (_length <= 2)
130-
return String.Empty;
127+
return string.Empty;
131128

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

134-
string reason;
135-
136-
return bytes.TryGetUTF8DecodedString (out reason)
131+
return bytes.TryGetUTF8DecodedString (out var reason)
137132
? reason
138-
: String.Empty;
133+
: string.Empty;
139134
}
140135
}
141136

142137
#endregion
143138

144139
#region Public Properties
145140

146-
public byte[] ApplicationData {
147-
get {
148-
return _extDataLength > 0
149-
? _data.SubArray (_extDataLength, _length - _extDataLength)
150-
: _data;
151-
}
152-
}
141+
public byte[] ApplicationData =>
142+
ExtensionDataLength > 0
143+
? _data.SubArray (ExtensionDataLength, _length - ExtensionDataLength)
144+
: _data;
153145

154-
public byte[] ExtensionData {
155-
get {
156-
return _extDataLength > 0
157-
? _data.SubArray (0, _extDataLength)
158-
: WebSocket.EmptyBytes;
159-
}
160-
}
146+
public byte[] ExtensionData =>
147+
ExtensionDataLength > 0
148+
? _data.SubArray (0, ExtensionDataLength)
149+
: WebSocket.EmptyBytes;
161150

162-
public ulong Length {
163-
get {
164-
return (ulong) _length;
165-
}
166-
}
151+
public ulong Length => (ulong) _length;
167152

168153
#endregion
169154

websocket-sharp/Server/HttpServer.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -830,7 +830,7 @@ private static HttpListener createListener (
830830
}
831831

832832
private void init (
833-
string hostname, System.Net.IPAddress address, int port, bool secure
833+
string hostname, System.Net.IPAddress address, int port, bool secure, bool wildcardServicesPath = false
834834
)
835835
{
836836
_hostname = hostname;
@@ -841,7 +841,7 @@ private void init (
841841
_docRootPath = "./Public";
842842
_listener = createListener (_hostname, _port, _secure);
843843
_log = _listener.Log;
844-
_services = new WebSocketServiceManager (_log);
844+
_services = new WebSocketServiceManager (_log, wildcardServicesPath);
845845
_sync = new object ();
846846
}
847847

0 commit comments

Comments
 (0)