diff --git a/Example/bin/Debug_Ubuntu/example.exe b/Example/bin/Debug_Ubuntu/example.exe index a035389f..10d42ef5 100755 Binary files a/Example/bin/Debug_Ubuntu/example.exe and b/Example/bin/Debug_Ubuntu/example.exe differ diff --git a/Example/bin/Debug_Ubuntu/websocket-sharp.dll b/Example/bin/Debug_Ubuntu/websocket-sharp.dll index 8b213901..77a44851 100755 Binary files a/Example/bin/Debug_Ubuntu/websocket-sharp.dll and b/Example/bin/Debug_Ubuntu/websocket-sharp.dll differ diff --git a/Example1/bin/Debug_Ubuntu/example1.exe b/Example1/bin/Debug_Ubuntu/example1.exe index 44628063..308ef52d 100755 Binary files a/Example1/bin/Debug_Ubuntu/example1.exe and b/Example1/bin/Debug_Ubuntu/example1.exe differ diff --git a/Example1/bin/Debug_Ubuntu/websocket-sharp.dll b/Example1/bin/Debug_Ubuntu/websocket-sharp.dll index 8b213901..77a44851 100755 Binary files a/Example1/bin/Debug_Ubuntu/websocket-sharp.dll and b/Example1/bin/Debug_Ubuntu/websocket-sharp.dll differ diff --git a/Example2/Chat.cs b/Example2/Chat.cs index 5fd3c229..c7d0c011 100644 --- a/Example2/Chat.cs +++ b/Example2/Chat.cs @@ -13,7 +13,7 @@ namespace Example2 { private string getName() { - return QueryString.Exists("name") + return QueryString.Contains("name") ? QueryString["name"] : "anon#" + getNum(); } diff --git a/Example2/Echo.cs b/Example2/Echo.cs index c7063c7d..130a934d 100644 --- a/Example2/Echo.cs +++ b/Example2/Echo.cs @@ -9,7 +9,7 @@ namespace Example2 { { protected override void OnMessage(MessageEventArgs e) { - var msg = QueryString.Exists("name") + var msg = QueryString.Contains("name") ? String.Format("'{0}' returns to {1}", e.Data, QueryString["name"]) : e.Data; Send(msg); diff --git a/Example2/bin/Debug_Ubuntu/example2.exe b/Example2/bin/Debug_Ubuntu/example2.exe index 4a133c17..df2caad4 100755 Binary files a/Example2/bin/Debug_Ubuntu/example2.exe and b/Example2/bin/Debug_Ubuntu/example2.exe differ diff --git a/Example2/bin/Debug_Ubuntu/websocket-sharp.dll b/Example2/bin/Debug_Ubuntu/websocket-sharp.dll index 8b213901..77a44851 100755 Binary files a/Example2/bin/Debug_Ubuntu/websocket-sharp.dll and b/Example2/bin/Debug_Ubuntu/websocket-sharp.dll differ diff --git a/Example3/Chat.cs b/Example3/Chat.cs index 85e920fe..c6e887e7 100644 --- a/Example3/Chat.cs +++ b/Example3/Chat.cs @@ -13,7 +13,7 @@ namespace Example3 { private string getName() { - return QueryString.Exists("name") + return QueryString.Contains("name") ? QueryString["name"] : "anon#" + getNum(); } diff --git a/Example3/Echo.cs b/Example3/Echo.cs index 48c36d64..365e1194 100644 --- a/Example3/Echo.cs +++ b/Example3/Echo.cs @@ -8,7 +8,7 @@ namespace Example3 { { protected override void OnMessage(MessageEventArgs e) { - var msg = QueryString.Exists("name") + var msg = QueryString.Contains("name") ? String.Format("'{0}' returns to {1}", e.Data, QueryString["name"]) : e.Data; Send(msg); diff --git a/Example3/bin/Debug_Ubuntu/Example3.exe b/Example3/bin/Debug_Ubuntu/Example3.exe index 1faf9d14..82ebaa2d 100755 Binary files a/Example3/bin/Debug_Ubuntu/Example3.exe and b/Example3/bin/Debug_Ubuntu/Example3.exe differ diff --git a/Example3/bin/Debug_Ubuntu/websocket-sharp.dll b/Example3/bin/Debug_Ubuntu/websocket-sharp.dll index 8b213901..77a44851 100755 Binary files a/Example3/bin/Debug_Ubuntu/websocket-sharp.dll and b/Example3/bin/Debug_Ubuntu/websocket-sharp.dll differ diff --git a/websocket-sharp/Ext.cs b/websocket-sharp/Ext.cs index 2fc0b1a6..8c1bdb87 100644 --- a/websocket-sharp/Ext.cs +++ b/websocket-sharp/Ext.cs @@ -479,6 +479,60 @@ namespace WebSocketSharp { : value.IndexOfAny(chars) != -1; } + /// + /// Determines whether the specified contains the entry + /// with the specified . + /// + /// + /// true if contains the entry with ; + /// otherwise, false. + /// + /// + /// A that contains the entries. + /// + /// + /// A that contains the key of the entry to find. + /// + public static bool Contains(this NameValueCollection collection, string name) + { + return collection == null + ? false + : collection[name] != null; + } + + /// + /// Determines whether the specified contains the entry + /// with the specified both and . + /// + /// + /// true if contains the entry with both and ; + /// otherwise, false. + /// + /// + /// A that contains the entries. + /// + /// + /// A that contains the key of the entry to find. + /// + /// + /// A that contains the value of the entry to find. + /// + public static bool Contains(this NameValueCollection collection, string name, string value) + { + if (collection == null) + return false; + + var values = collection[name]; + if (values == null) + return false; + + foreach (string v in values.Split(',')) + if (v.Trim().Equals(value, StringComparison.OrdinalIgnoreCase)) + return true; + + return false; + } + /// /// Emit the specified delegate if is not . /// @@ -551,56 +605,6 @@ namespace WebSocketSharp { return b == Convert.ToByte(c); } - /// - /// Determines whether the entry with the specified key exists in the specified . - /// - /// - /// true if the entry with the exists in the ; otherwise, false. - /// - /// - /// A that contains the entries. - /// - /// - /// A that contains the key of the entry to find. - /// - public static bool Exists(this NameValueCollection collection, string name) - { - return collection == null - ? false - : collection[name] != null; - } - - /// - /// Determines whether the entry with the specified both key and value exists in the specified . - /// - /// - /// true if the entry with the both and exists in the ; otherwise, false. - /// - /// - /// A that contains the entries. - /// - /// - /// A that contains the key of the entry to find. - /// - /// - /// A that contains the value of the entry to find. - /// - public static bool Exists(this NameValueCollection collection, string name, string value) - { - if (collection == null) - return false; - - var values = collection[name]; - if (values == null) - return false; - - foreach (string v in values.Split(',')) - if (String.Compare(v.Trim(), value, true) == 0) - return true; - - return false; - } - /// /// Gets the absolute path from the specified . /// @@ -645,10 +649,9 @@ namespace WebSocketSharp { public static CookieCollection GetCookies(this NameValueCollection headers, bool response) { var name = response ? "Set-Cookie" : "Cookie"; - if (headers == null || !headers.Exists(name)) - return new CookieCollection(); - - return CookieCollection.Parse(headers[name], response); + return headers == null || !headers.Contains(name) + ? new CookieCollection() + : CookieCollection.Parse(headers[name], response); } /// @@ -999,10 +1002,10 @@ namespace WebSocketSharp { if (protocol.Length == 0) throw new ArgumentException("Must not be empty.", "protocol"); - if (!request.Headers.Exists("Upgrade", protocol)) + if (!request.Headers.Contains("Upgrade", protocol)) return false; - if (!request.Headers.Exists("Connection", "Upgrade")) + if (!request.Headers.Contains("Connection", "Upgrade")) return false; return true; diff --git a/websocket-sharp/Handshake.cs b/websocket-sharp/Handshake.cs index d5310b74..692dce96 100644 --- a/websocket-sharp/Handshake.cs +++ b/websocket-sharp/Handshake.cs @@ -72,12 +72,12 @@ namespace WebSocketSharp { public bool ContainsHeader(string name) { - return Headers.Exists(name); + return Headers.Contains(name); } public bool ContainsHeader(string name, string value) { - return Headers.Exists(name, value); + return Headers.Contains(name, value); } public string[] GetHeaderValues(string name) diff --git a/websocket-sharp/Net/HttpListenerRequest.cs b/websocket-sharp/Net/HttpListenerRequest.cs index bc8df327..c9278e2f 100644 --- a/websocket-sharp/Net/HttpListenerRequest.cs +++ b/websocket-sharp/Net/HttpListenerRequest.cs @@ -265,15 +265,15 @@ namespace WebSocketSharp.Net { ? false : version < HttpVersion.Version11 ? false - : !headers.Exists("Upgrade", "websocket") + : !headers.Contains("Upgrade", "websocket") ? false - : !headers.Exists("Connection", "Upgrade") + : !headers.Contains("Connection", "Upgrade") ? false - : !headers.Exists("Host") + : !headers.Contains("Host") ? false - : !headers.Exists("Sec-WebSocket-Key") + : !headers.Contains("Sec-WebSocket-Key") ? false - : headers.Exists("Sec-WebSocket-Version"); + : headers.Contains("Sec-WebSocket-Version"); } } diff --git a/websocket-sharp/WebSocket.cs b/websocket-sharp/WebSocket.cs index 77c2ed29..dca631ad 100644 --- a/websocket-sharp/WebSocket.cs +++ b/websocket-sharp/WebSocket.cs @@ -819,7 +819,7 @@ namespace WebSocketSharp { ? false : !isValidHostHeader() ? false - : _context.Headers.Exists("Sec-WebSocket-Version", _version); + : _context.Headers.Contains("Sec-WebSocket-Version", _version); } // As client diff --git a/websocket-sharp/bin/Debug_Ubuntu/websocket-sharp.dll b/websocket-sharp/bin/Debug_Ubuntu/websocket-sharp.dll index 8b213901..77a44851 100755 Binary files a/websocket-sharp/bin/Debug_Ubuntu/websocket-sharp.dll and b/websocket-sharp/bin/Debug_Ubuntu/websocket-sharp.dll differ