Beispiel #1
0
        private IEnumerator UploadObjectTestTestInner(string url)
        {
            using (UnityWebRequestWrapper request = new UnityWebRequestWrapper(url, "PUT"))
            {
                yield return(request.Send());

                // verify the file is successfully put to the bucket
                if (request.IsError)
                {
                    Assert.Fail();
                }
            }
        }
Beispiel #2
0
        private IEnumerator DownloadObjectTestInner(string url)
        {
            using (UnityWebRequestWrapper request = new UnityWebRequestWrapper(url, "GET")) {
                yield return(request.Send());

                if (request.IsError)
                {
                    Assert.Fail();
                }
                else
                {
                    // verify the file get from the url is the one upload
                    byte[] dataGet = request.DownloadHandler.Data;
                    Assert.Equals(dataGet, System.IO.File.ReadAllBytes(FileName));
                }
            }
        }
        public UnityWebResponseData(UnityWebRequestWrapper unityWebRequest)
        {
            CopyHeaderValues(unityWebRequest.ResponseHeaders);
            if (!unityWebRequest.IsError)
            {
                _responseBody = unityWebRequest.DownloadHandler.Data;

                if (_responseBody == null)
                {
                    _responseBody = new byte[0];
                }

                _responseStream = new MemoryStream(_responseBody);

                this.ContentLength = _responseBody.LongLength;

                string contentType = null;

                this._headers.TryGetValue(HeaderKeys.ContentTypeHeader, out contentType);

                this.ContentType = contentType;

                if (unityWebRequest.StatusCode.HasValue)
                {
                    this.StatusCode = unityWebRequest.StatusCode.Value;
                }

                this.IsSuccessStatusCode = this.StatusCode >= HttpStatusCode.OK && this.StatusCode <= (HttpStatusCode)299;
            }
            else
            {
                this.IsSuccessStatusCode = false;
                this._responseBody       = UTF8Encoding.UTF8.GetBytes(unityWebRequest.Error);
                _responseStream          = new MemoryStream(_responseBody);

                if (unityWebRequest.DownloadedBytes > 0)
                {
                    this.ContentLength = (long)unityWebRequest.DownloadedBytes;
                }
                else
                {
                    string contentLength = null;
                    if (this._headers.TryGetValue(HeaderKeys.ContentLengthHeader, out contentLength))
                    {
                        long cl;
                        if (long.TryParse(contentLength, out cl))
                        {
                            this.ContentLength = cl;
                        }
                        else
                        {
                            this.ContentLength = 0;
                        }
                    }
                    else
                    {
                        this.ContentLength = this._responseBody.Length;
                    }
                }

                if (unityWebRequest.StatusCode.HasValue)
                {
                    this.StatusCode = unityWebRequest.StatusCode.Value;
                }
                else
                {
                    string statusCode = null;
                    if (this._headers.TryGetValue(HeaderKeys.StatusHeader, out statusCode))
                    {
                        this.StatusCode = (HttpStatusCode)Enum.Parse(typeof(HttpStatusCode), statusCode);
                    }
                    else
                    {
                        this.StatusCode = 0;
                    }
                }
            }
        }
        public UnityWebResponseData(UnityWebRequestWrapper unityWebRequest)
        {
            CopyHeaderValues(unityWebRequest.ResponseHeaders);
            if (!unityWebRequest.IsError)
            {
                _responseBody = unityWebRequest.DownloadHandler.Data;

                if (_responseBody == null)
                {
                    _responseBody = new byte[0];
                }

                _responseStream = new MemoryStream(_responseBody);

                this.ContentLength = _responseBody.LongLength;

                string contentType = null;

                this._headers.TryGetValue(HeaderKeys.ContentTypeHeader, out contentType);

                this.ContentType = contentType;

                if (unityWebRequest.StatusCode.HasValue)
                    this.StatusCode = unityWebRequest.StatusCode.Value;

                this.IsSuccessStatusCode = this.StatusCode >= HttpStatusCode.OK && this.StatusCode <= (HttpStatusCode)299;
            }
            else
            {
                this.IsSuccessStatusCode = false;
                this._responseBody = UTF8Encoding.UTF8.GetBytes(unityWebRequest.Error);
                _responseStream = new MemoryStream(_responseBody);
                
                if (unityWebRequest.DownloadedBytes > 0)
                {
                    this.ContentLength = (long)unityWebRequest.DownloadedBytes;
                }
                else
                {
                    string contentLength = null;
                    if (this._headers.TryGetValue(HeaderKeys.ContentLengthHeader, out contentLength))
                    {
                        long cl;
                        if(long.TryParse(contentLength,out cl))
                            this.ContentLength = cl;
                        else
                            this.ContentLength = 0;
                    }
                    else
                    {
                        this.ContentLength = this._responseBody.Length;
                    }
                }

                if (unityWebRequest.StatusCode.HasValue)
                {
                    this.StatusCode = unityWebRequest.StatusCode.Value;
                }
                else
                {
                    string statusCode = null;
                    if (this._headers.TryGetValue(HeaderKeys.StatusHeader, out statusCode))
                    {
                        this.StatusCode = (HttpStatusCode)Enum.Parse(typeof(HttpStatusCode), statusCode);
                    }
                    else
                    {
                        this.StatusCode = 0;
                    }
                }
            }
        }
 public UnityWebResponseData(UnityWebRequestWrapper unityWebRequest)
 {
     CopyHeaderValues(unityWebRequest.ResponseHeaders);
     if (!unityWebRequest.IsError)
     {
         _responseBody = unityWebRequest.DownloadHandler.Data;
         if (_responseBody == null)
         {
             _responseBody = new byte[0];
         }
         _responseStream = new MemoryStream(_responseBody);
         ContentLength   = _responseBody.LongLength;
         string value = null;
         _headers.TryGetValue("Content-Type", out value);
         ContentType = value;
         if (unityWebRequest.StatusCode.HasValue)
         {
             StatusCode = unityWebRequest.StatusCode.Value;
         }
         IsSuccessStatusCode = (StatusCode >= HttpStatusCode.OK && StatusCode <= (HttpStatusCode)299);
     }
     else
     {
         IsSuccessStatusCode = false;
         _responseBody       = Encoding.UTF8.GetBytes(unityWebRequest.Error);
         _responseStream     = new MemoryStream(_responseBody);
         if (unityWebRequest.DownloadedBytes != 0)
         {
             ContentLength = (long)unityWebRequest.DownloadedBytes;
         }
         else
         {
             string value2 = null;
             if (_headers.TryGetValue("Content-Length", out value2))
             {
                 if (long.TryParse(value2, out long result))
                 {
                     ContentLength = result;
                 }
                 else
                 {
                     ContentLength = 0L;
                 }
             }
             else
             {
                 ContentLength = _responseBody.Length;
             }
         }
         if (unityWebRequest.StatusCode.HasValue)
         {
             StatusCode = unityWebRequest.StatusCode.Value;
         }
         else
         {
             string value3 = null;
             if (_headers.TryGetValue("Status", out value3))
             {
                 StatusCode = (HttpStatusCode)Enum.Parse(typeof(HttpStatusCode), value3);
             }
             else
             {
                 StatusCode = (HttpStatusCode)0;
             }
         }
     }
 }