示例#1
0
        private WebGLHttpResponse CreateErrorResponse(Exception ex)
        {
            WebGLHttpResponse webGLHttpResponse = new WebGLHttpResponse();

            webGLHttpResponse.ResponseStatus = ResponseStatus.Error;
            return(webGLHttpResponse);
        }
示例#2
0
 private void ExtractResponseData(WebGLHttpResponse response, XmlHttpRequest webResponse)
 {
     if (webResponse.ResponseHeaders.ContainsKey("Content-Encoding"))
     {
         response.ContentEncoding = webResponse.ResponseHeaders["Content-Encoding"];
     }
     if (webResponse.ResponseHeaders.ContainsKey("Server"))
     {
         response.Server = webResponse.ResponseHeaders["Server"];
     }
     if (webResponse.ResponseHeaders.ContainsKey("Content-Type"))
     {
         response.ContentType = webResponse.ResponseHeaders["Content-Type"];
     }
     if (webResponse.ResponseHeaders.ContainsKey("Content-Length"))
     {
         response.ContentLength = Convert.ToInt64(webResponse.ResponseHeaders["Content-Length"]);
     }
     response.RawBytes          = webResponse.Response;
     response.StatusCode        = (HttpStatusCode)webResponse.Status;
     response.StatusDescription = webResponse.StatusLine;
     response.ResponseUri       = webResponse.Url;
     response.ResponseStatus    = ResponseStatus.Completed;
     foreach (string key in webResponse.ResponseHeaders.Keys)
     {
         string value = webResponse.ResponseHeaders[key];
         response.Headers.Add(new HttpHeader
         {
             Name  = key,
             Value = value
         });
     }
 }
示例#3
0
 private static void PopulateErrorForIncompleteResponse(WebGLHttpResponse response)
 {
     if (response.ResponseStatus != ResponseStatus.Completed && response.ErrorException == null)
     {
         response.ErrorException = response.ResponseStatus.ToWebException();
         response.ErrorMessage   = response.ErrorException.Message;
     }
 }
示例#4
0
        private void ResponseCallback(IAsyncResult result, Action <IHttpResponse> callback)
        {
            WebGLHttpResponse response = new WebGLHttpResponse
            {
                ResponseStatus = ResponseStatus.None,
                RequestId      = RequestId
            };

            try
            {
                GetRawResponseAsync(result, delegate(XmlHttpRequest webResponse)
                {
                    ExtractResponseData(response, webResponse);
                    logger.Debug(response);
                    ExecuteCallback(response, callback);
                });
            }
            catch (Exception ex)
            {
                Debug.LogException(ex);
                ExecuteCallback(CreateErrorResponse(ex), callback);
            }
        }
示例#5
0
 private static void ExecuteCallback(WebGLHttpResponse response, Action <IHttpResponse> callback)
 {
     PopulateErrorForIncompleteResponse(response);
     callback(response);
 }