public override IAsyncResult BeginGetResponse(AsyncCallback callback, object state) { bool send = (method == "PUT" || method == "POST"); if (send) { if ((!KeepAlive || (ContentLength == -1 && !SendChunked)) && !AllowWriteStreamBuffering) { throw new ProtocolViolationException("Content-Length not set"); } } CommonChecks(send); Monitor.Enter(this); getResponseCalled = true; if (asyncRead != null && !haveResponse) { Monitor.Exit(this); throw new InvalidOperationException("Cannot re-call start of asynchronous " + "method while a previous call is still in progress."); } CheckIfForceWrite(); asyncRead = new WebAsyncResult(this, callback, state); WebAsyncResult aread = asyncRead; initialMethod = method; if (haveResponse) { if (webResponse != null) { Exception saved = saved_exc; Monitor.Exit(this); if (saved == null) { aread.SetCompleted(true, webResponse); } else { aread.SetCompleted(true, saved); } aread.DoCallback(); return(aread); } } if (!requestSent) { requestSent = true; redirects = 0; servicePoint = GetServicePoint(); abortHandler = servicePoint.SendRequest(this, connectionGroup); } Monitor.Exit(this); return(aread); }
public override IAsyncResult BeginGetResponse (AsyncCallback callback, object state) { if (Aborted) throw new WebException ("The request was canceled.", WebExceptionStatus.RequestCanceled); if (method == null) throw new ProtocolViolationException ("Method is null."); string transferEncoding = TransferEncoding; if (!sendChunked && transferEncoding != null && transferEncoding.Trim () != "") throw new ProtocolViolationException ("SendChunked should be true."); Monitor.Enter (locker); getResponseCalled = true; if (asyncRead != null && !haveResponse) { Monitor.Exit (locker); throw new InvalidOperationException ("Cannot re-call start of asynchronous " + "method while a previous call is still in progress."); } CheckIfForceWrite (); asyncRead = new WebAsyncResult (this, callback, state); WebAsyncResult aread = asyncRead; initialMethod = method; if (haveResponse) { Exception saved = saved_exc; if (webResponse != null) { Monitor.Exit (locker); if (saved == null) { aread.SetCompleted (true, webResponse); } else { aread.SetCompleted (true, saved); } aread.DoCallback (); return aread; } else if (saved != null) { Monitor.Exit (locker); aread.SetCompleted (true, saved); aread.DoCallback (); return aread; } } if (!requestSent) { requestSent = true; redirects = 0; servicePoint = GetServicePoint (); abortHandler = servicePoint.SendRequest (this, connectionGroup); } Monitor.Exit (locker); return aread; }
public override IAsyncResult BeginGetRequestStream(AsyncCallback callback, object state) { if (aborted) { throw new WebException("The request was previosly aborted."); } bool send = !(method == "GET" || method == "CONNECT" || method == "HEAD" || method == "TRACE" || method == "DELETE"); if (method == null || !send) { throw new ProtocolViolationException("Cannot send data when method is: " + method); } CommonChecks(send); lock (locker) { if (asyncWrite != null) { throw new InvalidOperationException("Cannot re-call start of asynchronous " + "method while a previous call is still in progress."); } asyncWrite = new WebAsyncResult(this, callback, state); initialMethod = method; if (haveRequest) { if (writeStream != null) { asyncWrite.SetCompleted(true, writeStream); asyncWrite.DoCallback(); return(asyncWrite); } } gotRequestStream = true; WebAsyncResult result = asyncWrite; if (!requestSent) { requestSent = true; redirects = 0; servicePoint = GetServicePoint(); abortHandler = servicePoint.SendRequest(this, connectionGroup); } return(result); } }
public override IAsyncResult BeginGetRequestStream (AsyncCallback callback, object state) { if (Aborted) throw new WebException ("The request was canceled.", WebExceptionStatus.RequestCanceled); bool send = !(method == "GET" || method == "CONNECT" || method == "HEAD" || method == "TRACE"); if (method == null || !send) throw new ProtocolViolationException ("Cannot send data when method is: " + method); if (contentLength == -1 && !sendChunked && !allowBuffering && KeepAlive) throw new ProtocolViolationException ("Content-Length not set"); string transferEncoding = TransferEncoding; if (!sendChunked && transferEncoding != null && transferEncoding.Trim () != "") throw new ProtocolViolationException ("SendChunked should be true."); lock (locker) { if (asyncWrite != null) { throw new InvalidOperationException ("Cannot re-call start of asynchronous " + "method while a previous call is still in progress."); } asyncWrite = new WebAsyncResult (this, callback, state); initialMethod = method; if (haveRequest) { if (writeStream != null) { asyncWrite.SetCompleted (true, writeStream); asyncWrite.DoCallback (); return asyncWrite; } } gotRequestStream = true; WebAsyncResult result = asyncWrite; if (!requestSent) { requestSent = true; redirects = 0; servicePoint = GetServicePoint (); abortHandler = servicePoint.SendRequest (this, connectionGroup); } return result; } }
public override IAsyncResult BeginGetRequestStream (AsyncCallback callback, object state) { if (Aborted) throw new WebException ("The request was canceled.", WebExceptionStatus.RequestCanceled); bool send = !(method == "GET" || method == "CONNECT" || method == "HEAD" || method == "TRACE"); if (method == null || !send) throw new ProtocolViolationException ("Cannot send data when method is: " + method); if (contentLength == -1 && !sendChunked && !allowBuffering && KeepAlive) throw new ProtocolViolationException ("Content-Length not set"); string transferEncoding = TransferEncoding; if (!sendChunked && transferEncoding != null && transferEncoding.Trim () != "") throw new ProtocolViolationException ("SendChunked should be true."); lock (locker) { if (getResponseCalled) throw new InvalidOperationException ("The operation cannot be performed once the request has been submitted."); if (asyncWrite != null) { throw new InvalidOperationException ("Cannot re-call start of asynchronous " + "method while a previous call is still in progress."); } asyncWrite = new WebAsyncResult (this, callback, state); initialMethod = method; if (haveRequest) { if (writeStream != null) { asyncWrite.SetCompleted (true, writeStream); asyncWrite.DoCallback (); return asyncWrite; } } gotRequestStream = true; WebAsyncResult result = asyncWrite; if (!requestSent) { requestSent = true; redirects = 0; servicePoint = GetServicePoint (); abortHandler = servicePoint.SendRequest (this, connectionGroup); } return result; } }
internal void SetResponseData (WebConnectionData data) { lock (locker) { if (Aborted) { if (data.stream != null) data.stream.Close (); return; } WebException wexc = null; try { webResponse = new HttpWebResponse (actualUri, method, data, cookieContainer); } catch (Exception e) { wexc = new WebException (e.Message, e, WebExceptionStatus.ProtocolError, null); if (data.stream != null) data.stream.Close (); } if (wexc == null && (method == "POST" || method == "PUT")) { CheckSendError (data); if (saved_exc != null) wexc = (WebException) saved_exc; } WebAsyncResult r = asyncRead; bool forced = false; if (r == null && webResponse != null) { // This is a forced completion (302, 204)... forced = true; r = new WebAsyncResult (null, null); r.SetCompleted (false, webResponse); } if (r != null) { if (wexc != null) { haveResponse = true; if (!r.IsCompleted) r.SetCompleted (false, wexc); r.DoCallback (); return; } bool redirected; try { redirected = CheckFinalStatus (r); if (!redirected) { if (ntlm_auth_state != NtlmAuthState.None && authCompleted && webResponse != null && (int)webResponse.StatusCode < 400) { WebConnectionStream wce = webResponse.GetResponseStream () as WebConnectionStream; if (wce != null) { WebConnection cnc = wce.Connection; cnc.NtlmAuthenticated = true; } } // clear internal buffer so that it does not // hold possible big buffer (bug #397627) if (writeStream != null) writeStream.KillBuffer (); haveResponse = true; r.SetCompleted (false, webResponse); r.DoCallback (); } else { if (webResponse != null) { if (ntlm_auth_state != NtlmAuthState.None) { HandleNtlmAuth (r); return; } webResponse.Close (); } finished_reading = false; haveResponse = false; webResponse = null; r.Reset (); servicePoint = GetServicePoint (); abortHandler = servicePoint.SendRequest (this, connectionGroup); } } catch (WebException wexc2) { if (forced) { saved_exc = wexc2; haveResponse = true; } r.SetCompleted (false, wexc2); r.DoCallback (); return; } catch (Exception ex) { wexc = new WebException (ex.Message, ex, WebExceptionStatus.ProtocolError, null); if (forced) { saved_exc = wexc; haveResponse = true; } r.SetCompleted (false, wexc); r.DoCallback (); return; } } } }
void GetResponseAsyncCB2 (WebAsyncResult aread) { if (haveResponse) { Exception saved = saved_exc; if (webResponse != null) { Monitor.Exit (locker); if (saved == null) { aread.SetCompleted (true, webResponse); } else { aread.SetCompleted (true, saved); } aread.DoCallback (); return; } else if (saved != null) { Monitor.Exit (locker); aread.SetCompleted (true, saved); aread.DoCallback (); return; } } if (!requestSent) { requestSent = true; redirects = 0; servicePoint = GetServicePoint (); abortHandler = servicePoint.SendRequest (this, connectionGroup); } Monitor.Exit (locker); }
public override IAsyncResult BeginGetResponse (AsyncCallback callback, object state) { if (Aborted) throw new WebException ("The request was canceled.", WebExceptionStatus.RequestCanceled); if (method == null) throw new ProtocolViolationException ("Method is null."); #if !NET_2_0 bool send = !(method == "GET" || method == "CONNECT" || method == "HEAD" || method == "TRACE" || method == "DELETE"); if (send && contentLength < 0 && !sendChunked && !allowBuffering && KeepAlive) throw new ProtocolViolationException ("Buffering is disabled, ContentLength is negative and SendChunked is disabled."); if (!send && (contentLength > -1 || sendChunked)) throw new ProtocolViolationException ("ContentLength can't be set for non-write operations."); #endif string transferEncoding = TransferEncoding; if (!sendChunked && transferEncoding != null && transferEncoding.Trim () != "") throw new ProtocolViolationException ("SendChunked should be true."); Monitor.Enter (locker); getResponseCalled = true; if (asyncRead != null && !haveResponse) { Monitor.Exit (locker); throw new InvalidOperationException ("Cannot re-call start of asynchronous " + "method while a previous call is still in progress."); } CheckIfForceWrite (); asyncRead = new WebAsyncResult (this, callback, state); WebAsyncResult aread = asyncRead; initialMethod = method; if (haveResponse) { Exception saved = saved_exc; if (webResponse != null) { Monitor.Exit (locker); if (saved == null) { aread.SetCompleted (true, webResponse); } else { aread.SetCompleted (true, saved); } aread.DoCallback (); return aread; } else if (saved != null) { Monitor.Exit (locker); aread.SetCompleted (true, saved); aread.DoCallback (); return aread; } } if (!requestSent) { requestSent = true; redirects = 0; servicePoint = GetServicePoint (); abortHandler = servicePoint.SendRequest (this, connectionGroup); } Monitor.Exit (locker); return aread; }
internal void SetResponseData(WebConnectionData data) { if (aborted) { if (data.stream != null) { data.stream.Close(); } return; } WebException wexc = null; try { webResponse = new HttpWebResponse(actualUri, method, data, cookieContainer); haveResponse = true; } catch (Exception e) { wexc = new WebException(e.Message, e, WebExceptionStatus.ProtocolError, null); if (data.stream != null) { data.stream.Close(); } } if (wexc == null && (method == "POST" || method == "PUT")) { lock (locker) { CheckSendError(data); if (saved_exc != null) { wexc = (WebException)saved_exc; } } } WebAsyncResult r = asyncRead; if (r != null) { if (wexc != null) { r.SetCompleted(false, wexc); r.DoCallback(); return; } bool redirected; try { redirected = CheckFinalStatus(r); if (!redirected) { r.SetCompleted(false, webResponse); r.DoCallback(); } else { if (webResponse != null) { webResponse.Close(); webResponse = null; } haveResponse = false; webResponse = null; r.Reset(); servicePoint = GetServicePoint(); abortHandler = servicePoint.SendRequest(this, connectionGroup); } } catch (WebException wexc2) { r.SetCompleted(false, wexc2); r.DoCallback(); return; } catch (Exception ex) { wexc = new WebException(ex.Message, ex, WebExceptionStatus.ProtocolError, null); r.SetCompleted(false, wexc); r.DoCallback(); return; } } }