private WebGLHttpResponse CreateErrorResponse(Exception ex) { WebGLHttpResponse webGLHttpResponse = new WebGLHttpResponse(); webGLHttpResponse.ResponseStatus = ResponseStatus.Error; return(webGLHttpResponse); }
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 }); } }
private static void PopulateErrorForIncompleteResponse(WebGLHttpResponse response) { if (response.ResponseStatus != ResponseStatus.Completed && response.ErrorException == null) { response.ErrorException = response.ResponseStatus.ToWebException(); response.ErrorMessage = response.ErrorException.Message; } }
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); } }
private static void ExecuteCallback(WebGLHttpResponse response, Action <IHttpResponse> callback) { PopulateErrorForIncompleteResponse(response); callback(response); }