diff --git a/README.md b/README.md index ec7d56c..8640e88 100644 --- a/README.md +++ b/README.md @@ -103,6 +103,7 @@ RestClient.Request(new RequestHelper { BodyString = "Use it instead of 'Body' if you want to use other tool to serialize the JSON", SimpleForm = new Dictionary {}, //Content-Type: application/x-www-form-urlencoded FormSections = new List() {}, //Content-Type: multipart/form-data + DownloadHandler = new DownloadHandlerFile(destPah), //Download large files ChunkedTransfer = true, IgnoreHttpException = true //Prevent to catch http exceptions }).Then(response => { diff --git a/src/Proyecto26.RestClient/Properties/AssemblyInfo.cs b/src/Proyecto26.RestClient/Properties/AssemblyInfo.cs index 39941ae..86d52f0 100644 --- a/src/Proyecto26.RestClient/Properties/AssemblyInfo.cs +++ b/src/Proyecto26.RestClient/Properties/AssemblyInfo.cs @@ -17,7 +17,7 @@ // The form "{Major}.{Minor}.*" will automatically update the build and revision, // and "{Major}.{Minor}.{Build}.*" will update just the revision. -[assembly: AssemblyVersion ("2.1.0")] +[assembly: AssemblyVersion ("2.1.1")] // The following attributes are used to specify the signing key for the assembly, // if desired. See the Mono documentation for more information about signing. diff --git a/src/Proyecto26.RestClient/Proyecto26.RestClient.nuspec b/src/Proyecto26.RestClient/Proyecto26.RestClient.nuspec index f4489e9..d57e075 100644 --- a/src/Proyecto26.RestClient/Proyecto26.RestClient.nuspec +++ b/src/Proyecto26.RestClient/Proyecto26.RestClient.nuspec @@ -2,7 +2,7 @@ Proyecto26.RestClient - 2.1.0 + 2.1.1 RestClient for Unity Juan David Nicholls Cardona jdnichollsc diff --git a/src/Proyecto26.RestClient/Utils/Extensions.cs b/src/Proyecto26.RestClient/Utils/Extensions.cs index b64264f..85766ac 100644 --- a/src/Proyecto26.RestClient/Utils/Extensions.cs +++ b/src/Proyecto26.RestClient/Utils/Extensions.cs @@ -65,7 +65,7 @@ public static IEnumerator SendWebRequest(this UnityWebRequest request, RequestHe { request.chunkedTransfer = options.ChunkedTransfer.Value; } - options.request = request; + options.Request = request; yield return request.SendWebRequest(); } @@ -76,14 +76,7 @@ public static IEnumerator SendWebRequest(this UnityWebRequest request, RequestHe /// An UnityWebRequest object. public static ResponseHelper CreateWebResponse(this UnityWebRequest request) { - return new ResponseHelper - { - StatusCode = request.responseCode, - Data = request.downloadHandler.data, - Text = request.downloadHandler.text, - Headers = request.GetResponseHeaders(), - Error = request.error - }; + return new ResponseHelper(request); } public static bool IsValidRequest(this UnityWebRequest request, RequestHelper options) diff --git a/src/Proyecto26.RestClient/Utils/RequestHelper.cs b/src/Proyecto26.RestClient/Utils/RequestHelper.cs index 9ebfff5..a9d2db9 100644 --- a/src/Proyecto26.RestClient/Utils/RequestHelper.cs +++ b/src/Proyecto26.RestClient/Utils/RequestHelper.cs @@ -96,9 +96,9 @@ public float UploadProgress get { float progress = 0; - if(this.request != null) + if(this.Request != null) { - progress = this.request.uploadProgress; + progress = this.Request.uploadProgress; } return progress; } @@ -109,9 +109,9 @@ public float DownloadProgress get { float progress = 0; - if (this.request != null) + if (this.Request != null) { - progress = this.request.downloadProgress; + progress = this.Request.downloadProgress; } return progress; } @@ -120,7 +120,7 @@ public float DownloadProgress /// /// Internal use /// - public UnityWebRequest request { private get; set; } + public UnityWebRequest Request { private get; set; } /// /// Get the value of a header @@ -130,9 +130,9 @@ public float DownloadProgress public string GetHeader(string name) { string headerValue; - if (request != null) + if (this.Request != null) { - headerValue = request.GetRequestHeader(name); + headerValue = this.Request.GetRequestHeader(name); } else { @@ -145,9 +145,16 @@ public string GetHeader(string name) /// Abort the request manually /// public void Abort() { - if (this.request != null) + if (this.Request != null) { - this.request.Abort(); + try + { + this.Request.Abort(); + } + finally + { + this.Request = null; + } } } } diff --git a/src/Proyecto26.RestClient/Utils/ResponseHelper.cs b/src/Proyecto26.RestClient/Utils/ResponseHelper.cs index 4af3c5a..967b2c5 100644 --- a/src/Proyecto26.RestClient/Utils/ResponseHelper.cs +++ b/src/Proyecto26.RestClient/Utils/ResponseHelper.cs @@ -1,52 +1,66 @@ using System; using UnityEngine; using System.Collections.Generic; +using UnityEngine.Networking; namespace Proyecto26 { [Serializable] public class ResponseHelper { - private long _statusCode; + private UnityWebRequest request { get; set; } + + public ResponseHelper(UnityWebRequest unityWebRequest) + { + request = unityWebRequest; + } + public long StatusCode { - get { return _statusCode; } - set { _statusCode = value; } + get { return request.responseCode; } } - private byte[] _data; public byte[] Data { - get { return _data; } - set { _data = value; } + get { + byte[] _data; + try + { + _data = request.downloadHandler.data; + } + catch (Exception) + { + _data = null; + } + return _data; + } } - private string _text; public string Text { - get { return _text; } - set { _text = value; } + get + { + string _text; + try + { + _text = request.downloadHandler.text; + } + catch (Exception) + { + _text = string.Empty; + } + return _text; + } } - private string _error; public string Error { - get { return _error; } - set { _error = value; } + get { return request.error; } } - private Dictionary _headers; public Dictionary Headers { - get - { - if (_headers == null) - { - _headers = new Dictionary(); - } - return _headers; - } - set { _headers = value; } + get { return request.GetResponseHeaders(); } } public override string ToString()