public override WebResponse EndGetResponse(IAsyncResult asyncResult) { try { if (async_result != asyncResult) { throw new ArgumentException("asyncResult"); } if (aborted) { NativeMethods.http_request_abort(native); throw new WebException("Aborted", WebExceptionStatus.RequestCanceled); } if (!async_result.IsCompleted) { async_result.AsyncWaitHandle.WaitOne(); } if (async_result.HasException) { throw async_result.Exception; } response = async_result.Response as BrowserHttpWebResponse; } finally { async_result.Dispose(); managed.Free(); } return(response); }
void OnAsyncDataAvailable(IntPtr sender, IntPtr calldata, IntPtr closure) { IntPtr data = IntPtr.Zero; uint length = 0; BrowserHttpWebResponse response = async_result.Response as BrowserHttpWebResponse; try { data = NativeMethods.http_request_write_event_args_get_data(calldata); length = NativeMethods.http_request_write_event_args_get_count(calldata); bytes_read += length; if (progress != null) { // if Content-Encoding is gzip (or other compressed) then Content-Length cannot be trusted, // if present, since it does not (generally) correspond to the uncompressed length long content_length = response.ContentLength; bool compressed = (response.IsCompressed || (content_length == 0)); long total_bytes_to_receive = compressed ? -1 : content_length; progress(bytes_read, total_bytes_to_receive); } } catch (Exception e) { async_result.Exception = e; } try { if (data != IntPtr.Zero && length != 0) { response.Write(data, checked ((int)length)); } } catch (Exception e) { async_result.Exception = e; } }
private void FlashPolicyCallback(IAsyncResult result) { WebRequest wreq = (result.AsyncState as WebRequest); BrowserHttpWebResponse wres = (BrowserHttpWebResponse)wreq.EndGetResponse(result); // we either got a Flash policy or (if none/bad) a NoAccessPolicy, either way we continue... policy = CrossDomainPolicyManager.BuildFlashPolicy(wres); GetResponse(this.Method, uri, true); }
static void OnHttpHeader(IntPtr context, IntPtr name, IntPtr value) { try { BrowserHttpWebResponse response = (BrowserHttpWebResponse)GCHandle.FromIntPtr(context).Target; response.InternalHeaders [Marshal.PtrToStringAnsi(name)] = Marshal.PtrToStringAnsi(value); } catch { // dont leak exceptions to native code } }
void OnAsyncResponseStopped(IntPtr sender, IntPtr calldata, IntPtr closure) { try { if (progress != null) { BrowserHttpWebResponse response = async_result.Response as BrowserHttpWebResponse; // report the 100% progress on compressed (or without Content-Length) if (response.IsCompressed) { long length = response.ContentLength; progress(length, length); } } } finally { async_result.SetComplete(); } }
private void SilverlightPolicyCallback(IAsyncResult result) { WebRequest wreq = (result.AsyncState as WebRequest); BrowserHttpWebResponse wres = (BrowserHttpWebResponse)wreq.EndGetResponse(result); policy = CrossDomainPolicyManager.BuildSilverlightPolicy(wres); if (policy != null) { // we got our policy so we can proceed with the main request GetResponse(this.Method, uri, true); } else { // no policy but we get a second chance to try a Flash policy Uri flash_policy_uri = CrossDomainPolicyManager.GetFlashPolicyUri(wres.ResponseUri); BrowserHttpWebRequestInternal preq = new BrowserHttpWebRequestInternal(null, flash_policy_uri); preq.BeginGetResponse(new AsyncCallback(FlashPolicyCallback), preq); } }
public override WebResponse EndGetResponse (IAsyncResult asyncResult) { try { if (async_result != asyncResult) throw new ArgumentException ("asyncResult"); if (aborted) { NativeMethods.http_request_abort (native); throw new WebException ("Aborted", WebExceptionStatus.RequestCanceled); } if (!async_result.IsCompleted) async_result.AsyncWaitHandle.WaitOne (); if (async_result.HasException) { throw async_result.Exception; } response = async_result.Response as BrowserHttpWebResponse; } finally { async_result.Dispose (); managed.Free (); } return response; }