diff --git a/Example/bin/Debug_Ubuntu/example.exe b/Example/bin/Debug_Ubuntu/example.exe index b16a2f0f..f6d8a82b 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/example.exe.mdb b/Example/bin/Debug_Ubuntu/example.exe.mdb index 73482c0e..48d9f9b0 100644 Binary files a/Example/bin/Debug_Ubuntu/example.exe.mdb and b/Example/bin/Debug_Ubuntu/example.exe.mdb differ diff --git a/Example/bin/Debug_Ubuntu/websocket-sharp.dll b/Example/bin/Debug_Ubuntu/websocket-sharp.dll index 50cf103d..e52c67b3 100755 Binary files a/Example/bin/Debug_Ubuntu/websocket-sharp.dll and b/Example/bin/Debug_Ubuntu/websocket-sharp.dll differ diff --git a/Example/bin/Debug_Ubuntu/websocket-sharp.dll.mdb b/Example/bin/Debug_Ubuntu/websocket-sharp.dll.mdb index a0464ecb..c952480f 100644 Binary files a/Example/bin/Debug_Ubuntu/websocket-sharp.dll.mdb and b/Example/bin/Debug_Ubuntu/websocket-sharp.dll.mdb differ diff --git a/Example1/bin/Debug_Ubuntu/example1.exe b/Example1/bin/Debug_Ubuntu/example1.exe index 9a8fbd12..ec8c0d47 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/example1.exe.mdb b/Example1/bin/Debug_Ubuntu/example1.exe.mdb index b798d91a..941a29b7 100644 Binary files a/Example1/bin/Debug_Ubuntu/example1.exe.mdb and b/Example1/bin/Debug_Ubuntu/example1.exe.mdb differ diff --git a/Example1/bin/Debug_Ubuntu/websocket-sharp.dll b/Example1/bin/Debug_Ubuntu/websocket-sharp.dll index 50cf103d..e52c67b3 100755 Binary files a/Example1/bin/Debug_Ubuntu/websocket-sharp.dll and b/Example1/bin/Debug_Ubuntu/websocket-sharp.dll differ diff --git a/Example1/bin/Debug_Ubuntu/websocket-sharp.dll.mdb b/Example1/bin/Debug_Ubuntu/websocket-sharp.dll.mdb index a0464ecb..c952480f 100644 Binary files a/Example1/bin/Debug_Ubuntu/websocket-sharp.dll.mdb and b/Example1/bin/Debug_Ubuntu/websocket-sharp.dll.mdb differ diff --git a/Example2/bin/Debug_Ubuntu/example2.exe b/Example2/bin/Debug_Ubuntu/example2.exe index c31b318b..e1fa3de4 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/example2.exe.mdb b/Example2/bin/Debug_Ubuntu/example2.exe.mdb index b4844258..7e1e77ab 100644 Binary files a/Example2/bin/Debug_Ubuntu/example2.exe.mdb and b/Example2/bin/Debug_Ubuntu/example2.exe.mdb differ diff --git a/Example2/bin/Debug_Ubuntu/websocket-sharp.dll b/Example2/bin/Debug_Ubuntu/websocket-sharp.dll index 50cf103d..e52c67b3 100755 Binary files a/Example2/bin/Debug_Ubuntu/websocket-sharp.dll and b/Example2/bin/Debug_Ubuntu/websocket-sharp.dll differ diff --git a/Example2/bin/Debug_Ubuntu/websocket-sharp.dll.mdb b/Example2/bin/Debug_Ubuntu/websocket-sharp.dll.mdb index a0464ecb..c952480f 100644 Binary files a/Example2/bin/Debug_Ubuntu/websocket-sharp.dll.mdb and b/Example2/bin/Debug_Ubuntu/websocket-sharp.dll.mdb differ diff --git a/Example3/bin/Debug_Ubuntu/Example3.exe b/Example3/bin/Debug_Ubuntu/Example3.exe index 92451554..29338e41 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/Example3.exe.mdb b/Example3/bin/Debug_Ubuntu/Example3.exe.mdb index 78ef7c2f..e25a657c 100644 Binary files a/Example3/bin/Debug_Ubuntu/Example3.exe.mdb and b/Example3/bin/Debug_Ubuntu/Example3.exe.mdb differ diff --git a/Example3/bin/Debug_Ubuntu/websocket-sharp.dll b/Example3/bin/Debug_Ubuntu/websocket-sharp.dll index 50cf103d..e52c67b3 100755 Binary files a/Example3/bin/Debug_Ubuntu/websocket-sharp.dll and b/Example3/bin/Debug_Ubuntu/websocket-sharp.dll differ diff --git a/Example3/bin/Debug_Ubuntu/websocket-sharp.dll.mdb b/Example3/bin/Debug_Ubuntu/websocket-sharp.dll.mdb index a0464ecb..c952480f 100644 Binary files a/Example3/bin/Debug_Ubuntu/websocket-sharp.dll.mdb and b/Example3/bin/Debug_Ubuntu/websocket-sharp.dll.mdb differ diff --git a/websocket-sharp/Net/WebHeaderCollection.cs b/websocket-sharp/Net/WebHeaderCollection.cs index 32a72964..352a74ce 100644 --- a/websocket-sharp/Net/WebHeaderCollection.cs +++ b/websocket-sharp/Net/WebHeaderCollection.cs @@ -425,29 +425,23 @@ namespace WebSocketSharp.Net { void Add (string name, string value, bool ignoreRestricted) { - name = Trim (name); - CheckName (name); - Action add; if (ignoreRestricted) add = AddWithoutCheckingNameAndRestricted; else add = AddWithoutCheckingName; - DoWithCheckingState (add, name, value); + DoWithCheckingState (add, CheckName (name), value, true); } void AddWithoutCheckingName (string name, string value) { - CheckRestricted (name); - AddWithoutCheckingNameAndRestricted (name, value); + DoWithoutCheckingName (base.Add, name, value); } void AddWithoutCheckingNameAndRestricted (string name, string value) { - value = Trim (value); - CheckValue (value); - base.Add (name, value); + base.Add (name, CheckValue (value)); } static int CheckColonSeparated (string header) @@ -459,13 +453,28 @@ namespace WebSocketSharp.Net { return i; } - static void CheckName (string name) + static HttpHeaderType CheckHeaderType (string name) + { + HttpHeaderInfo info; + return !TryGetHeaderInfo (name, out info) + ? HttpHeaderType.Undefined + : info.IsRequest && !info.IsResponse + ? HttpHeaderType.Request + : !info.IsRequest && info.IsResponse + ? HttpHeaderType.Response + : HttpHeaderType.Undefined; + } + + static string CheckName (string name) { + name = Trim (name); if (name.IsEmpty ()) throw new ArgumentNullException ("name"); if (!IsHeaderName (name)) throw new ArgumentException ("Contains invalid characters.", "name"); + + return name; } void CheckRestricted (string name) @@ -486,22 +495,19 @@ namespace WebSocketSharp.Net { throw new InvalidOperationException ("This collection has already been used to store the response headers."); } - void CheckState (HttpHeaderInfo info) + static string CheckValue (string value) { - if (info.IsRequest && !info.IsResponse) - CheckState (false); - - if (!info.IsRequest && info.IsResponse) - CheckState (true); - } + value = Trim (value); + if (value.IsEmpty ()) + return value; - static void CheckValue (string value) - { if (value.Length > 65535) throw new ArgumentOutOfRangeException ("value", "The length must not be greater than 65535."); if (!IsHeaderValue (value)) throw new ArgumentException ("Contains invalid characters.", "value"); + + return value; } static string Convert (HttpRequestHeader header) @@ -530,18 +536,31 @@ namespace WebSocketSharp.Net { : false; } - void DoWithCheckingState (Action act, string name, string value) + void DoWithCheckingState ( + Action act, string name, string value, bool setState) { - HttpHeaderInfo info; - if (TryGetHeaderInfo (name, out info)) - { - CheckState (info); + var type = CheckHeaderType (name); + if (type == HttpHeaderType.Request) + DoWithCheckingState (act, name, value, false, setState); + else if (type == HttpHeaderType.Response) + DoWithCheckingState (act, name, value, true, setState); + else act (name, value); - SetState (info); - return; - } + } + void DoWithCheckingState ( + Action act, string name, string value, bool response, bool setState) + { + CheckState (response); act (name, value); + if (setState) + SetState (response); + } + + void DoWithoutCheckingName (Action act, string name, string value) + { + CheckRestricted (name); + act (name, CheckValue (value)); } static HttpHeaderInfo GetHeaderInfo (string name) @@ -551,7 +570,7 @@ namespace WebSocketSharp.Net { select info).FirstOrDefault (); } - void RemoveWithoutCheckingName (string name) + void RemoveWithoutCheckingName (string name, string unuse) { CheckRestricted (name); base.Remove (name); @@ -565,21 +584,9 @@ namespace WebSocketSharp.Net { : HttpHeaderType.Request; } - void SetState (HttpHeaderInfo info) - { - if (info.IsRequest && !info.IsResponse) - SetState (false); - - if (!info.IsRequest && info.IsResponse) - SetState (true); - } - void SetWithoutCheckingName (string name, string value) { - CheckRestricted (name); - value = Trim (value); - CheckValue (value); - base.Set (name, value); + DoWithoutCheckingName (base.Set, name, value); } static string Trim (string value) @@ -637,9 +644,7 @@ namespace WebSocketSharp.Net { internal void SetInternal (string name, string value, bool response) { - value = Trim (value); - CheckValue (value); - + value = CheckValue (value); if (IsMultiValue (name, response)) base.Add (name, value); else @@ -790,9 +795,7 @@ namespace WebSocketSharp.Net { /// public void Add (HttpRequestHeader header, string value) { - CheckState (false); - AddWithoutCheckingName (Convert (header), value); - SetState (false); + DoWithCheckingState (AddWithoutCheckingName, Convert (header), value, false, true); } /// @@ -823,9 +826,7 @@ namespace WebSocketSharp.Net { /// public void Add (HttpResponseHeader header, string value) { - CheckState (true); - AddWithoutCheckingName (Convert (header), value); - SetState (true); + DoWithCheckingState (AddWithoutCheckingName, Convert (header), value, true, true); } /// @@ -1031,9 +1032,7 @@ namespace WebSocketSharp.Net { /// public static bool IsRestricted (string headerName, bool response) { - var name = Trim (headerName); - CheckName (name); - return ContainsInRestricted (name, response); + return ContainsInRestricted (CheckName (headerName), response); } /// @@ -1061,8 +1060,7 @@ namespace WebSocketSharp.Net { /// public void Remove (HttpRequestHeader header) { - CheckState (false); - RemoveWithoutCheckingName (Convert (header)); + DoWithCheckingState (RemoveWithoutCheckingName, Convert (header), null, false, false); } /// @@ -1079,8 +1077,7 @@ namespace WebSocketSharp.Net { /// public void Remove (HttpResponseHeader header) { - CheckState (true); - RemoveWithoutCheckingName (Convert (header)); + DoWithCheckingState (RemoveWithoutCheckingName, Convert (header), null, true, false); } /// @@ -1108,14 +1105,7 @@ namespace WebSocketSharp.Net { /// public override void Remove (string name) { - name = Trim (name); - CheckName (name); - - HttpHeaderInfo info; - if (TryGetHeaderInfo (name, out info)) - CheckState (info); - - RemoveWithoutCheckingName (name); + DoWithCheckingState (RemoveWithoutCheckingName, CheckName (name), null, false); } /// @@ -1146,9 +1136,7 @@ namespace WebSocketSharp.Net { /// public void Set (HttpRequestHeader header, string value) { - CheckState (false); - SetWithoutCheckingName (Convert (header), value); - SetState (false); + DoWithCheckingState (SetWithoutCheckingName, Convert (header), value, false, true); } /// @@ -1179,9 +1167,7 @@ namespace WebSocketSharp.Net { /// public void Set (HttpResponseHeader header, string value) { - CheckState (true); - SetWithoutCheckingName (Convert (header), value); - SetState (true); + DoWithCheckingState (SetWithoutCheckingName, Convert (header), value, true, true); } /// @@ -1215,9 +1201,7 @@ namespace WebSocketSharp.Net { /// public override void Set (string name, string value) { - name = Trim (name); - CheckName (name); - DoWithCheckingState (SetWithoutCheckingName, name, value); + DoWithCheckingState (SetWithoutCheckingName, CheckName (name), value, true); } /// diff --git a/websocket-sharp/bin/Debug_Ubuntu/websocket-sharp.dll b/websocket-sharp/bin/Debug_Ubuntu/websocket-sharp.dll index 50cf103d..e52c67b3 100755 Binary files a/websocket-sharp/bin/Debug_Ubuntu/websocket-sharp.dll and b/websocket-sharp/bin/Debug_Ubuntu/websocket-sharp.dll differ diff --git a/websocket-sharp/bin/Debug_Ubuntu/websocket-sharp.dll.mdb b/websocket-sharp/bin/Debug_Ubuntu/websocket-sharp.dll.mdb index a0464ecb..c952480f 100644 Binary files a/websocket-sharp/bin/Debug_Ubuntu/websocket-sharp.dll.mdb and b/websocket-sharp/bin/Debug_Ubuntu/websocket-sharp.dll.mdb differ diff --git a/websocket-sharp/websocket-sharp.pidb b/websocket-sharp/websocket-sharp.pidb index cde0d606..1d9c22dc 100644 Binary files a/websocket-sharp/websocket-sharp.pidb and b/websocket-sharp/websocket-sharp.pidb differ