From da254a322ac1d106bebc38d6b8bf689a9d3a8c60 Mon Sep 17 00:00:00 2001 From: Rouven Malecki Date: Fri, 29 Nov 2013 12:29:04 +0100 Subject: [PATCH 01/12] =?UTF-8?q?Fix=20ResponseCallbackDispatcher=20initia?= =?UTF-8?q?lization=20check=20(cannot=20use=20null=20comparison=20outside?= =?UTF-8?q?=20Unity=E2=80=99s=20main=20thread)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Request.cs | 2 +- ResponseCallbackDispatcher.cs | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/Request.cs b/Request.cs index 3d13b7c..332abbb 100644 --- a/Request.cs +++ b/Request.cs @@ -242,7 +242,7 @@ private void GetResponse() { public void Send( Action< HTTP.Request > callback ) { - if (!synchronous && callback != null && ResponseCallbackDispatcher.Singleton == null ) + if (!synchronous && callback != null && !ResponseCallbackDispatcher.IsInitialized) { ResponseCallbackDispatcher.Init(); } diff --git a/ResponseCallbackDispatcher.cs b/ResponseCallbackDispatcher.cs index f938cec..ed420d0 100644 --- a/ResponseCallbackDispatcher.cs +++ b/ResponseCallbackDispatcher.cs @@ -9,7 +9,9 @@ public class ResponseCallbackDispatcher : MonoBehaviour private static ResponseCallbackDispatcher singleton = null; private static GameObject singletonGameObject = null; private static object singletonLock = new object(); - + + public static bool IsInitialized { get; set; } + public static ResponseCallbackDispatcher Singleton { get { return singleton; @@ -35,6 +37,7 @@ public static void Init() singletonGameObject = new GameObject(); singleton = singletonGameObject.AddComponent< ResponseCallbackDispatcher >(); singletonGameObject.name = "HTTPResponseCallbackDispatcher"; + IsInitialized = true; } } From e3f4d934443deb56f15d681fc7308487a84943e0 Mon Sep 17 00:00:00 2001 From: Rouven Malecki Date: Fri, 29 Nov 2013 14:04:46 +0100 Subject: [PATCH 02/12] reverse init change --- Request.cs | 2 +- ResponseCallbackDispatcher.cs | 5 +---- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/Request.cs b/Request.cs index 332abbb..3d13b7c 100644 --- a/Request.cs +++ b/Request.cs @@ -242,7 +242,7 @@ private void GetResponse() { public void Send( Action< HTTP.Request > callback ) { - if (!synchronous && callback != null && !ResponseCallbackDispatcher.IsInitialized) + if (!synchronous && callback != null && ResponseCallbackDispatcher.Singleton == null ) { ResponseCallbackDispatcher.Init(); } diff --git a/ResponseCallbackDispatcher.cs b/ResponseCallbackDispatcher.cs index ed420d0..f938cec 100644 --- a/ResponseCallbackDispatcher.cs +++ b/ResponseCallbackDispatcher.cs @@ -9,9 +9,7 @@ public class ResponseCallbackDispatcher : MonoBehaviour private static ResponseCallbackDispatcher singleton = null; private static GameObject singletonGameObject = null; private static object singletonLock = new object(); - - public static bool IsInitialized { get; set; } - + public static ResponseCallbackDispatcher Singleton { get { return singleton; @@ -37,7 +35,6 @@ public static void Init() singletonGameObject = new GameObject(); singleton = singletonGameObject.AddComponent< ResponseCallbackDispatcher >(); singletonGameObject.name = "HTTPResponseCallbackDispatcher"; - IsInitialized = true; } } From 1c7fb69b92d1964baadae55cfb768c165279de3e Mon Sep 17 00:00:00 2001 From: Rouven Malecki Date: Sat, 25 Jan 2014 19:10:50 +0100 Subject: [PATCH 03/12] Remove SSL debug output --- Request.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Request.cs b/Request.cs index 3d13b7c..d900231 100644 --- a/Request.cs +++ b/Request.cs @@ -305,7 +305,7 @@ public static bool ValidateServerCertificate (object sender, X509Certificate cer #if !UNITY_EDITOR System.Console.WriteLine( "NET: SSL Cert: " + sslPolicyErrors.ToString() ); #else - Debug.LogWarning("SSL Cert Error: " + sslPolicyErrors.ToString ()); + //Debug.LogWarning("SSL Cert Error: " + sslPolicyErrors.ToString ()); #endif return true; } From 487d10f89119643603dab481b2e2468ff613c16c Mon Sep 17 00:00:00 2001 From: Rouven Malecki Date: Mon, 10 Mar 2014 09:26:59 +0100 Subject: [PATCH 04/12] Fix number parsing (floating point cast is wrong for integers > 24bit!) --- external/JSON.cs | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/external/JSON.cs b/external/JSON.cs index 5c3fb00..2b66c9a 100644 --- a/external/JSON.cs +++ b/external/JSON.cs @@ -271,14 +271,18 @@ protected static object ParseNumber (char[] json, ref int index, ref bool succes int lastIndex = GetLastIndexOfNumber (json, index); int charLength = (lastIndex - index) + 1; - float number; var token = new string (json, index, charLength); - success = float.TryParse (token, NumberStyles.Any, CultureInfo.InvariantCulture, out number); - index = lastIndex + 1; - if(token.Contains(".")) - return (float)number; - else - return (int)number; + if (token.Contains(".")) { + float number; + success = float.TryParse (token, NumberStyles.Any, CultureInfo.InvariantCulture, out number); + index = lastIndex + 1; + return number; + } else { + int number; + success = int.TryParse(token, out number); + index = lastIndex + 1; + return number; + } } protected static int GetLastIndexOfNumber (char[] json, int index) From 17631b293a1fec45dcd02d912cce12230640691a Mon Sep 17 00:00:00 2001 From: Rouven Malecki Date: Tue, 10 Jun 2014 11:25:57 +0200 Subject: [PATCH 05/12] Parse e-notation float when "e" is found in token --- external/JSON.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/external/JSON.cs b/external/JSON.cs index 2b66c9a..b70b31b 100644 --- a/external/JSON.cs +++ b/external/JSON.cs @@ -272,7 +272,7 @@ protected static object ParseNumber (char[] json, ref int index, ref bool succes int charLength = (lastIndex - index) + 1; var token = new string (json, index, charLength); - if (token.Contains(".")) { + if (token.Contains(".") || ((token.Contains("e") || token.Contains("E")) && !token.StartsWith("0x"))) { float number; success = float.TryParse (token, NumberStyles.Any, CultureInfo.InvariantCulture, out number); index = lastIndex + 1; From a80a5c79130fa912ea955b219292e980992d79e7 Mon Sep 17 00:00:00 2001 From: Rouven Malecki Date: Thu, 7 May 2015 15:39:07 +0200 Subject: [PATCH 06/12] support for parsing longs --- external/JSON.cs | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/external/JSON.cs b/external/JSON.cs index b70b31b..2ac4e8f 100644 --- a/external/JSON.cs +++ b/external/JSON.cs @@ -278,10 +278,16 @@ protected static object ParseNumber (char[] json, ref int index, ref bool succes index = lastIndex + 1; return number; } else { - int number; - success = int.TryParse(token, out number); index = lastIndex + 1; - return number; + int number32; + success = int.TryParse(token, out number32); + if (success) { + return number32; + } + + long number64; + success = long.TryParse(token, out number64); + return number64; } } From f6fbd628f9f20581c576afcca43c23bb8b98882b Mon Sep 17 00:00:00 2001 From: Rouven Malecki Date: Tue, 19 May 2015 09:06:46 +0200 Subject: [PATCH 07/12] Unity 5 compatibility --- Request.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Request.cs b/Request.cs index d900231..6e42709 100644 --- a/Request.cs +++ b/Request.cs @@ -75,9 +75,9 @@ public Request( string method, string uri, WWWForm form ) this.method = method; this.uri = new Uri (uri); this.bytes = form.data; - foreach ( DictionaryEntry entry in form.headers ) + foreach ( KeyValuePair entry in form.headers ) { - this.AddHeader( (string)entry.Key, (string)entry.Value ); + this.AddHeader(entry.Key, entry.Value ); } } From 4c3c8cc4764c2673b88a40ba80ba2900ed25e737 Mon Sep 17 00:00:00 2001 From: Rouven Malecki Date: Thu, 21 Jul 2016 22:58:22 +0200 Subject: [PATCH 08/12] Remove StreamedWWWForm (not compatible with Web Player) --- src/Request.cs | 10 ------- src/StreamedWWWForm.cs | 62 ------------------------------------------ 2 files changed, 72 deletions(-) delete mode 100644 src/StreamedWWWForm.cs diff --git a/src/Request.cs b/src/Request.cs index 2d86473..3b307bd 100644 --- a/src/Request.cs +++ b/src/Request.cs @@ -74,16 +74,6 @@ public Request (string method, string uri, byte[] bytes) this.byteStream = new MemoryStream(bytes); } - public Request(string method, string uri, StreamedWWWForm form){ - this.method = method; - this.uri = new Uri (uri); - this.byteStream = form.stream; - foreach ( DictionaryEntry entry in form.headers ) - { - this.AddHeader( (string)entry.Key, (string)entry.Value ); - } - } - public Request( string method, string uri, WWWForm form ) { this.method = method; diff --git a/src/StreamedWWWForm.cs b/src/StreamedWWWForm.cs deleted file mode 100644 index 0510e48..0000000 --- a/src/StreamedWWWForm.cs +++ /dev/null @@ -1,62 +0,0 @@ -using System; -using System.IO; -using System.Text; -using System.Collections; - -namespace UnityHTTP -{ - public class StreamedWWWForm { - string boundary; - public FormDataStream stream; - - public Hashtable headers { - get { - return new Hashtable { - { "Content-Type", "multipart/form-data; boundary=\"" + boundary + "\""} - }; - } - } - - public StreamedWWWForm(){ - byte[] bytes = new byte[40]; - var random = new Random(); - for (int i=0; i<40; i++){ - bytes[i] = (byte)(48 + random.Next(62)); - if (bytes[i] > 57){ - bytes[i] += 7; - } - if (bytes[i] > 90){ - bytes[i] += 6; - } - } - boundary = Encoding.ASCII.GetString(bytes); - stream = new FormDataStream(boundary); - } - - public void AddField(string fieldName, string fieldValue){ - var contentStream = new MemoryStream(Encoding.UTF8.GetBytes(fieldValue)); - stream.AddPart(fieldName, "text/plain; charset=\"utf-8\"", contentStream); - - } - public void AddBinaryData(string fieldName, byte[] contents=null, string mimeType = null){ - var contentStream = new MemoryStream(contents); - if (mimeType == null){ - mimeType = "application/octet-stream"; - } - stream.AddPart(fieldName, mimeType, contentStream, fieldName + ".dat"); - } - public void AddBinaryData(string fieldName, Stream contents=null, string mimeType = null){ - if (mimeType == null){ - mimeType = "application/octet-stream"; - } - stream.AddPart(fieldName, mimeType, contents, fieldName + ".dat"); - } - public void AddFile(string fieldName, string path, string mimeType=null){ - if (mimeType == null){ - mimeType = "application/octet-stream"; - } - var contents = new FileInfo(path).Open(FileMode.Open); - stream.AddPart(fieldName, mimeType, contents, fieldName + ".dat"); - } - } -} From 545d03d7942b5176a3945809ba88e77c936ee5f2 Mon Sep 17 00:00:00 2001 From: Rouven Malecki Date: Mon, 25 Jul 2016 16:02:21 +0200 Subject: [PATCH 09/12] Fix long number parsing --- lib/JSON.cs | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/lib/JSON.cs b/lib/JSON.cs index f775dc7..ea014eb 100644 --- a/lib/JSON.cs +++ b/lib/JSON.cs @@ -279,18 +279,18 @@ protected static object ParseNumber (char[] json, ref int index, ref bool succes success = float.TryParse (token, NumberStyles.Any, CultureInfo.InvariantCulture, out number); return number; } - else if(token.Length <= 10) - { - int number; - success = int.TryParse(token, out number); - return number; - } else { - long number; - success = long.TryParse(token, out number); - return number; - } + int number32; + success = int.TryParse(token, out number32); + if (success) { + return number32; + } + + long number64; + success = long.TryParse(token, out number64); + return number64; + } } protected static int GetLastIndexOfNumber (char[] json, int index) From b5cc9b833bbfd73ee1d81bf0fd8483fde15116e6 Mon Sep 17 00:00:00 2001 From: Rouven Malecki Date: Fri, 12 Jan 2018 17:34:37 +0100 Subject: [PATCH 10/12] API update --- src/Request.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Request.cs b/src/Request.cs index 3b307bd..9e9ed6c 100644 --- a/src/Request.cs +++ b/src/Request.cs @@ -79,7 +79,7 @@ public Request( string method, string uri, WWWForm form ) this.method = method; this.uri = new Uri (uri); this.byteStream = new MemoryStream(form.data); -#if UNITY_5 +#if UNITY_5 || UNITY_2017 foreach ( var entry in form.headers ) { this.AddHeader( entry.Key, entry.Value ); From f43b2772dd5a4385fb1bf2f7bf8d5220b64338b9 Mon Sep 17 00:00:00 2001 From: Rouven Date: Mon, 5 Nov 2018 18:08:38 +0100 Subject: [PATCH 11/12] Unity 2018 compiler flag --- src/Request.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Request.cs b/src/Request.cs index 9e9ed6c..1b3059f 100644 --- a/src/Request.cs +++ b/src/Request.cs @@ -79,7 +79,7 @@ public Request( string method, string uri, WWWForm form ) this.method = method; this.uri = new Uri (uri); this.byteStream = new MemoryStream(form.data); -#if UNITY_5 || UNITY_2017 +#if UNITY_5 || UNITY_2017 || UNITY_2018 foreach ( var entry in form.headers ) { this.AddHeader( entry.Key, entry.Value ); From 9cadf880652da9e985bdb24b1c541b6041edb79d Mon Sep 17 00:00:00 2001 From: rr_rouven Date: Fri, 15 Feb 2019 20:33:34 +0100 Subject: [PATCH 12/12] future-proof compiler switch --- src/Request.cs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/Request.cs b/src/Request.cs index 1b3059f..aab7299 100644 --- a/src/Request.cs +++ b/src/Request.cs @@ -79,15 +79,15 @@ public Request( string method, string uri, WWWForm form ) this.method = method; this.uri = new Uri (uri); this.byteStream = new MemoryStream(form.data); -#if UNITY_5 || UNITY_2017 || UNITY_2018 - foreach ( var entry in form.headers ) +#if UNITY_4 + foreach ( DictionaryEntry entry in form.headers ) { - this.AddHeader( entry.Key, entry.Value ); + this.AddHeader( (string)entry.Key, (string)entry.Value ); } #else - foreach ( DictionaryEntry entry in form.headers ) + foreach (var entry in form.headers) { - this.AddHeader( (string)entry.Key, (string)entry.Value ); + this.AddHeader(entry.Key, entry.Value); } #endif }