Skip to content

Commit 94cf881

Browse files
committed
Fix for issue #15
1 parent cbaa540 commit 94cf881

File tree

83 files changed

+985
-118
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

83 files changed

+985
-118
lines changed

Example/Example.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@
5454
<Reference Include="notify-sharp, Version=0.4.0.0, Culture=neutral, PublicKeyToken=2df29c54e245917a">
5555
<Package>notify-sharp</Package>
5656
</Reference>
57+
<Reference Include="System.Core" />
5758
</ItemGroup>
5859
<ItemGroup>
5960
<ProjectReference Include="..\websocket-sharp\websocket-sharp.csproj">

Example/Example.pidb

78 Bytes
Binary file not shown.

Example/Program.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,10 @@
33
#endif
44
using System;
55
using System.Collections;
6+
using System.Linq;
67
using System.Threading;
78
using WebSocketSharp;
9+
using WebSocketSharp.Net;
810

911
namespace Example
1012
{
@@ -109,6 +111,8 @@ public static void Main(string[] args)
109111
"notification-message-im");
110112
};
111113

114+
//ws.SetCookie(new Cookie("nobita", "idiot"));
115+
//ws.SetCookie(new Cookie("dora", "tanuki"));
112116
ws.Connect();
113117

114118
Thread.Sleep(500);

Example/bin/Debug/example.exe

0 Bytes
Binary file not shown.

Example/bin/Debug/example.exe.mdb

31 Bytes
Binary file not shown.

Example/bin/Debug/websocket-sharp.dll

6.5 KB
Binary file not shown.
2.21 KB
Binary file not shown.

Example/bin/Debug_Ubuntu/example.exe

0 Bytes
Binary file not shown.
31 Bytes
Binary file not shown.
6.5 KB
Binary file not shown.
2.21 KB
Binary file not shown.

Example/bin/Release/example.exe

0 Bytes
Binary file not shown.
6.5 KB
Binary file not shown.
0 Bytes
Binary file not shown.
6.5 KB
Binary file not shown.

Example1/Example1.pidb

57 Bytes
Binary file not shown.

Example1/bin/Debug/example1.exe

0 Bytes
Binary file not shown.

Example1/bin/Debug/example1.exe.mdb

0 Bytes
Binary file not shown.
6.5 KB
Binary file not shown.
2.21 KB
Binary file not shown.
0 Bytes
Binary file not shown.
0 Bytes
Binary file not shown.
6.5 KB
Binary file not shown.
Binary file not shown.

Example1/bin/Release/example1.exe

0 Bytes
Binary file not shown.
6.5 KB
Binary file not shown.
0 Bytes
Binary file not shown.
Binary file not shown.

Example2/Echo.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System;
22
using WebSocketSharp;
3+
using WebSocketSharp.Net;
34
using WebSocketSharp.Server;
45

56
namespace Example2 {
@@ -13,5 +14,16 @@ protected override void OnMessage(MessageEventArgs e)
1314
: e.Data;
1415
Send(msg);
1516
}
17+
18+
protected override bool ProcessCookies(CookieCollection request, CookieCollection response)
19+
{
20+
foreach (Cookie cookie in request)
21+
{
22+
cookie.Expired = true;
23+
response.Add(cookie);
24+
}
25+
26+
return true;
27+
}
1628
}
1729
}

Example2/Example2.pidb

300 Bytes
Binary file not shown.

Example2/bin/Debug/example2.exe

0 Bytes
Binary file not shown.

Example2/bin/Debug/example2.exe.mdb

113 Bytes
Binary file not shown.
6.5 KB
Binary file not shown.
2.21 KB
Binary file not shown.
0 Bytes
Binary file not shown.
113 Bytes
Binary file not shown.
6.5 KB
Binary file not shown.
Binary file not shown.

Example2/bin/Release/example2.exe

0 Bytes
Binary file not shown.
6.5 KB
Binary file not shown.
0 Bytes
Binary file not shown.
Binary file not shown.

Example3/bin/Debug/Example3.exe

0 Bytes
Binary file not shown.

Example3/bin/Debug/Example3.exe.mdb

0 Bytes
Binary file not shown.
6.5 KB
Binary file not shown.
2.21 KB
Binary file not shown.
0 Bytes
Binary file not shown.
0 Bytes
Binary file not shown.
6.5 KB
Binary file not shown.
Binary file not shown.

Example3/bin/Release/Example3.exe

0 Bytes
Binary file not shown.
6.5 KB
Binary file not shown.
0 Bytes
Binary file not shown.
Binary file not shown.

websocket-sharp/Ext.cs

Lines changed: 43 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,22 @@ private static void times(this ulong n, Action act)
7373

7474
#region Internal Method
7575

76+
internal static string GetNameInternal(this string nameAndValue, string separator)
77+
{
78+
int i = nameAndValue.IndexOf(separator);
79+
return i > 0
80+
? nameAndValue.Substring(0, i).Trim()
81+
: null;
82+
}
83+
84+
internal static string GetValueInternal(this string nameAndValue, string separator)
85+
{
86+
int i = nameAndValue.IndexOf(separator);
87+
return i >= 0 && i < nameAndValue.Length - 1
88+
? nameAndValue.Substring(i + 1).Trim()
89+
: null;
90+
}
91+
7692
internal static bool IsText(this string value)
7793
{
7894
int len = value.Length;
@@ -100,7 +116,7 @@ internal static bool IsToken(this string value)
100116
{
101117
foreach (char c in value)
102118
{
103-
if (c < 0x20 || c >= 0x7f || _tspecials.Contains (c))
119+
if (c < 0x20 || c >= 0x7f || _tspecials.Contains(c))
104120
return false;
105121
}
106122

@@ -337,6 +353,28 @@ public static string GetAbsolutePath(this Uri uri)
337353
: uriString;
338354
}
339355

356+
/// <summary>
357+
/// Gets the collection of cookies from the specified <see cref="NameValueCollection"/>.
358+
/// </summary>
359+
/// <returns>
360+
/// A <see cref="CookieCollection"/> that receives a collection of the HTTP Cookies.
361+
/// </returns>
362+
/// <param name="headers">
363+
/// A <see cref="NameValueCollection"/> that contains a collection of the HTTP Headers.
364+
/// </param>
365+
/// <param name="response">
366+
/// <c>true</c> if gets from the response <paramref name="headers"/>;
367+
/// from the request <paramref name="headers"/>, <c>false</c>.
368+
/// </param>
369+
public static CookieCollection GetCookies(this NameValueCollection headers, bool response)
370+
{
371+
var name = response ? "Set-Cookie" : "Cookie";
372+
if (headers.IsNull() || !headers.Exists(name))
373+
return new CookieCollection();
374+
375+
return CookieCollection.Parse(headers[name], response);
376+
}
377+
340378
/// <summary>
341379
/// Gets the description of the HTTP status code using the specified <see cref="WebSocketSharp.Net.HttpStatusCode"/>.
342380
/// </summary>
@@ -365,15 +403,8 @@ public static string GetDescription(this HttpStatusCode code)
365403
/// </param>
366404
public static string GetName(this string nameAndValue, string separator)
367405
{
368-
if (nameAndValue.IsNullOrEmpty())
369-
return null;
370-
371-
if (separator.IsNullOrEmpty())
372-
return null;
373-
374-
var i = nameAndValue.IndexOf(separator);
375-
return i > 0
376-
? nameAndValue.Substring(0, i).Trim()
406+
return !nameAndValue.IsNullOrEmpty() && !separator.IsNullOrEmpty()
407+
? nameAndValue.GetNameInternal(separator)
377408
: null;
378409
}
379410

@@ -476,15 +507,8 @@ public static string GetStatusDescription(this int code)
476507
/// </param>
477508
public static string GetValue(this string nameAndValue, string separator)
478509
{
479-
if (nameAndValue.IsNullOrEmpty())
480-
return null;
481-
482-
if (separator.IsNullOrEmpty())
483-
return null;
484-
485-
var i = nameAndValue.IndexOf(separator);
486-
return i >= 0 && i < nameAndValue.Length - 1
487-
? nameAndValue.Substring(i + 1).Trim()
510+
return !nameAndValue.IsNullOrEmpty() && !separator.IsNullOrEmpty()
511+
? nameAndValue.GetValueInternal(separator)
488512
: null;
489513
}
490514

websocket-sharp/Handshake.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
*
55
* The MIT License
66
*
7-
* Copyright (c) 2012 sta.blockhead
7+
* Copyright (c) 2012-2013 sta.blockhead
88
*
99
* Permission is hereby granted, free of charge, to any person obtaining a copy
1010
* of this software and associated documentation files (the "Software"), to deal

0 commit comments

Comments
 (0)