//
 // Constructors
 //
 internal ConnectionGroup(ServicePoint servicePoint, string connName) {
     m_ServicePoint      = servicePoint;
     m_ConnectionLimit   = servicePoint.ConnectionLimit;
     m_ConnectionList    = new ArrayList(DefaultConnectionListSize); //it may grow beyond
     m_Name              = MakeQueryStr(connName);
     m_AbortDelegate     = new HttpAbortDelegate(Abort);
     GlobalLog.Print("ConnectionGroup::.ctor m_ConnectionLimit:" + m_ConnectionLimit.ToString());
 }
 internal ConnectionGroup(System.Net.ServicePoint servicePoint, string connName)
 {
     this.m_ServicePoint = servicePoint;
     this.m_ConnectionLimit = servicePoint.ConnectionLimit;
     this.m_ConnectionList = new ArrayList(3);
     this.m_Name = MakeQueryStr(connName);
     this.m_AbortDelegate = new HttpAbortDelegate(this.Abort);
 }
Beispiel #3
0
 internal ConnectionGroup(System.Net.ServicePoint servicePoint, string connName)
 {
     this.m_ServicePoint    = servicePoint;
     this.m_ConnectionLimit = servicePoint.ConnectionLimit;
     this.m_ConnectionList  = new ArrayList(3);
     this.m_Name            = MakeQueryStr(connName);
     this.m_AbortDelegate   = new HttpAbortDelegate(this.Abort);
 }
        //
        // FindServicePoint - Query using an Uri for a given server point
        //

        /// <devdoc>
        /// <para>Findes an existing <see cref='System.Net.ServicePoint'/> or creates a new <see cref='System.Net.ServicePoint'/> to manage communications to the specified <see cref='System.Uri'/>
        /// instance.</para>
        /// </devdoc>
        public static ServicePoint FindServicePoint(Uri address, IWebProxy proxy)
        {
            ProxyChain        chain;
            HttpAbortDelegate abortDelegate = null;
            int abortState = 0;

            return(FindServicePoint(address, proxy, out chain, ref abortDelegate, ref abortState));
        }
Beispiel #5
0
 //
 // Constructors
 //
 internal ConnectionGroup(ServicePoint servicePoint, string connName)
 {
     m_ServicePoint    = servicePoint;
     m_ConnectionLimit = servicePoint.ConnectionLimit;
     m_ConnectionList  = new ArrayList(DefaultConnectionListSize);   //it may grow beyond
     m_Name            = MakeQueryStr(connName);
     m_AbortDelegate   = new HttpAbortDelegate(Abort);
     GlobalLog.Print("ConnectionGroup::.ctor m_ConnectionLimit:" + m_ConnectionLimit.ToString());
 }
 //
 // Constructors
 //
 internal ConnectionGroup(ServicePoint servicePoint, string connName) {
     m_ServicePoint      = servicePoint;
     m_ConnectionLimit   = servicePoint.ConnectionLimit;
     m_ConnectionList    = new ArrayList(DefaultConnectionListSize); //it may grow beyond
     m_Name              = MakeQueryStr(connName);
     m_AbortDelegate     = new HttpAbortDelegate(Abort);
     GlobalLog.Print("ConnectionGroup::.ctor m_ConnectionLimit:" + m_ConnectionLimit.ToString());
     // Don't start the idle timer.  This group is technically idle, but it will be put to use 
     // immediately and has nothing to clean up right now.
 }
Beispiel #7
0
 //
 // Constructors
 //
 internal ConnectionGroup(ServicePoint servicePoint, string connName)
 {
     m_ServicePoint    = servicePoint;
     m_ConnectionLimit = servicePoint.ConnectionLimit;
     m_ConnectionList  = new ArrayList(DefaultConnectionListSize);   //it may grow beyond
     m_Name            = MakeQueryStr(connName);
     m_AbortDelegate   = new HttpAbortDelegate(Abort);
     GlobalLog.Print("ConnectionGroup::.ctor m_ConnectionLimit:" + m_ConnectionLimit.ToString());
     // Don't start the idle timer.  This group is technically idle, but it will be put to use
     // immediately and has nothing to clean up right now.
 }
Beispiel #8
0
        //
        // Constructors
        //

        internal ConnectionGroup(
            ServicePoint servicePoint,
            IPAddress ipAddress,
            int connectionLimit,
            String connName)
        {
            m_ServicePoint     = servicePoint;
            m_ConnectionLimit  = connectionLimit;
            m_UserDefinedLimit = servicePoint.UserDefinedLimit;
            m_ConnectionList   = new ArrayList(defConnectionListSize);  //it may grow beyond
            m_IPAddress        = ipAddress;
            m_Name             = MakeQueryStr(connName);
            m_AbortDelegate    = new HttpAbortDelegate(Abort);

            GlobalLog.Print("ConnectionGroup::.ctor m_ConnectionLimit:" + m_ConnectionLimit.ToString());
        }
        // If abortState becomes non-zero, the attempt to find a service point has been aborted.
        internal static ServicePoint FindServicePoint(Uri address, IWebProxy proxy, out ProxyChain chain, ref HttpAbortDelegate abortDelegate, ref int abortState)
        {
            if (address == null)
            {
                throw new ArgumentNullException("address");
            }
            GlobalLog.Enter("ServicePointManager::FindServicePoint() address:" + address.ToString());

            bool isProxyServicePoint = false;

            chain = null;

            //
            // find proxy info, and then switch on proxy
            //
            Uri proxyAddress = null;

            if (proxy != null && !address.IsLoopback)
            {
                IAutoWebProxy autoProxy = proxy as IAutoWebProxy;
                if (autoProxy != null)
                {
                    chain = autoProxy.GetProxies(address);

                    // Set up our ability to abort this MoveNext call.  Note that the current implementations of ProxyChain will only
                    // take time on the first call, so this is the only place we do this.  If a new ProxyChain takes time in later
                    // calls, this logic should be copied to other places MoveNext is called.
                    GlobalLog.Assert(abortDelegate == null, "ServicePointManager::FindServicePoint()|AbortDelegate already set.");
                    abortDelegate = chain.HttpAbortDelegate;
                    try
                    {
                        Thread.MemoryBarrier();
                        if (abortState != 0)
                        {
                            Exception exception = new WebException(NetRes.GetWebStatusString(WebExceptionStatus.RequestCanceled), WebExceptionStatus.RequestCanceled);
                            GlobalLog.LeaveException("ServicePointManager::FindServicePoint() Request aborted before proxy lookup.", exception);
                            throw exception;
                        }

                        if (!chain.Enumerator.MoveNext())
                        {
                            GlobalLog.Assert("ServicePointManager::FindServicePoint()|GetProxies() returned zero proxies.");

/*
 *                          Exception exception = new WebException(NetRes.GetWebStatusString(WebExceptionStatus.RequestProhibitedByProxy), WebExceptionStatus.RequestProhibitedByProxy);
 *                          GlobalLog.LeaveException("ServicePointManager::FindServicePoint() Proxy prevented request.", exception);
 *                          throw exception;
 */
                        }
                        proxyAddress = chain.Enumerator.Current;
                    }
                    finally
                    {
                        abortDelegate = null;
                    }
                }
                else if (!proxy.IsBypassed(address))
                {
                    // use proxy support
                    // rework address
                    proxyAddress = proxy.GetProxy(address);
                }

                // null means DIRECT
                if (proxyAddress != null)
                {
                    address             = proxyAddress;
                    isProxyServicePoint = true;
                }
            }

            ServicePoint servicePoint = FindServicePointHelper(address, isProxyServicePoint);

            GlobalLog.Leave("ServicePointManager::FindServicePoint() servicePoint#" + ValidationHelper.HashString(servicePoint));
            return(servicePoint);
        }
Beispiel #10
0
        internal static ServicePoint FindServicePoint(Uri address, IWebProxy proxy, out ProxyChain chain, ref HttpAbortDelegate abortDelegate, ref int abortState)
        {
            if (address == null)
            {
                throw new ArgumentNullException("address");
            }
            bool isProxyServicePoint = false;

            chain = null;
            Uri current = null;

            if ((proxy != null) && !address.IsLoopback)
            {
                IAutoWebProxy proxy2 = proxy as IAutoWebProxy;
                if (proxy2 != null)
                {
                    chain         = proxy2.GetProxies(address);
                    abortDelegate = chain.HttpAbortDelegate;
                    try
                    {
                        Thread.MemoryBarrier();
                        if (abortState != 0)
                        {
                            Exception exception = new WebException(NetRes.GetWebStatusString(WebExceptionStatus.RequestCanceled), WebExceptionStatus.RequestCanceled);
                            throw exception;
                        }
                        chain.Enumerator.MoveNext();
                        current = chain.Enumerator.Current;
                    }
                    finally
                    {
                        abortDelegate = null;
                    }
                }
                else if (!proxy.IsBypassed(address))
                {
                    current = proxy.GetProxy(address);
                }
                if (current != null)
                {
                    address             = current;
                    isProxyServicePoint = true;
                }
            }
            return(FindServicePointHelper(address, isProxyServicePoint));
        }
        internal Connection(ConnectionGroup connectionGroup) : base(null) {
            //
            // add this Connection to the pool in the connection group,
            //  keep a weak reference to it
            //
            m_MaximumUnauthorizedUploadLength = SettingsSectionInternal.Section.MaximumUnauthorizedUploadLength;
            if(m_MaximumUnauthorizedUploadLength > 0){
                m_MaximumUnauthorizedUploadLength*=1024;
            }
            m_ResponseData = new CoreResponseData();
            m_ConnectionGroup = connectionGroup;
            m_ReadBuffer = new byte[4096];    // Using a fixed 4k read buffer.
            m_ReadState = ReadState.Start;
            m_WaitList = new List<WaitListItem>();
            m_WriteList = new ArrayList();
            m_AbortDelegate = new HttpAbortDelegate(AbortOrDisassociate);
            m_ConnectionUnlock = new UnlockConnectionDelegate(UnlockRequest);

            // for status line parsing
            m_StatusLineValues = new StatusLineValues();
            m_RecycleTimer = ConnectionGroup.ServicePoint.ConnectionLeaseTimerQueue.CreateTimer();
            // the following line must be the last line of the constructor
            ConnectionGroup.Associate(this);
            m_ReadDone = true;
            m_WriteDone = true;
            m_Error = WebExceptionStatus.Success;
        }
Beispiel #12
0
        public Connection(
            ConnectionGroup   connectionGroup,
            ServicePoint      servicePoint,
            IPAddress         remoteAddress,
            Version           version,
            bool              supportsPipeline ) {

            //
            // add this Connection to the pool in the connection group,
            //  keep a weak reference to it
            //

            m_ConnectionGroup = connectionGroup;
            m_WeakReference = new WeakReference(this);
            m_ConnectionGroup.Associate(m_WeakReference);

            m_Idle = true;
            m_Free = true;
            m_CanPipeline = supportsPipeline;
            m_Server = servicePoint;
            m_Version = version;
            m_ReadBuffer = new byte[m_ReadBufferSize];
            m_CurrentRequestIndex = 0;
            m_ReadState = ReadState.Start;
            m_WaitList = new ArrayList();
            m_WriteList = new ArrayList();
            m_ReadCallbackEvent = new ManualResetEvent(true);

            m_StartConnectionDelegate = new WaitOrTimerCallback(StartConnectionCallback);
            m_AbortDelegate = new HttpAbortDelegate(Abort);

            // for status line parsing
            m_StatusLineInts = new int[MaxStatusInts];
            InitializeParseStatueLine();
        }
Beispiel #13
0
        internal Connection(ConnectionGroup connectionGroup) : base(null) {
            //
            // add this Connection to the pool in the connection group,
            //  keep a weak reference to it
            //
            m_MaximumUnauthorizedUploadLength = SettingsSectionInternal.Section.MaximumUnauthorizedUploadLength;
            if(m_MaximumUnauthorizedUploadLength > 0){
                m_MaximumUnauthorizedUploadLength*=1024;
            }
            m_ResponseData = new CoreResponseData();
            m_ConnectionGroup = connectionGroup;
            m_ReadBuffer = s_PinnableBufferCache.AllocateBuffer();
            m_ReadBufferFromPinnableCache = true;
            m_ReadState = ReadState.Start;
            m_WaitList = new List<WaitListItem>();
            m_WriteList = new ArrayList();
            m_AbortDelegate = new HttpAbortDelegate(AbortOrDisassociate);
            m_ConnectionUnlock = new UnlockConnectionDelegate(UnlockRequest);

            // for status line parsing
            m_StatusLineValues = new StatusLineValues();
            m_RecycleTimer = ConnectionGroup.ServicePoint.ConnectionLeaseTimerQueue.CreateTimer();
            // the following line must be the last line of the constructor
            ConnectionGroup.Associate(this);
            m_ReadDone = true;
            m_WriteDone = true;
            m_Error = WebExceptionStatus.Success;
            if (PinnableBufferCacheEventSource.Log.IsEnabled())
            {
                PinnableBufferCacheEventSource.Log.DebugMessage1("CTOR: In System.Net.Connection.Connnection", this.GetHashCode());
            }
        }
 internal Connection(System.Net.ConnectionGroup connectionGroup) : base(null)
 {
     this.m_IISVersion = -1;
     this.m_Free = true;
     this.m_Idle = true;
     this.m_KeepAlive = true;
     this.m_MaximumUnauthorizedUploadLength = SettingsSectionInternal.Section.MaximumUnauthorizedUploadLength;
     if (this.m_MaximumUnauthorizedUploadLength > 0L)
     {
         this.m_MaximumUnauthorizedUploadLength *= 0x400L;
     }
     this.m_ResponseData = new CoreResponseData();
     this.m_ConnectionGroup = connectionGroup;
     this.m_ReadBuffer = new byte[0x1000];
     this.m_ReadState = ReadState.Start;
     this.m_WaitList = new List<WaitListItem>();
     this.m_WriteList = new ArrayList();
     this.m_AbortDelegate = new HttpAbortDelegate(this.AbortOrDisassociate);
     this.m_ConnectionUnlock = new UnlockConnectionDelegate(this.UnlockRequest);
     this.m_StatusLineValues = new StatusLineValues();
     this.m_RecycleTimer = this.ConnectionGroup.ServicePoint.ConnectionLeaseTimerQueue.CreateTimer();
     this.ConnectionGroup.Associate(this);
     this.m_ReadDone = true;
     this.m_WriteDone = true;
     this.m_Error = WebExceptionStatus.Success;
 }
Beispiel #15
0
        /*++

        Routine Description:

            ClearRequestForResubmit - prepares object for resubmission and recall
                of submit request, for redirects, authentication, and other uses
                This is needed to prevent duplicate headers being added, and other
                such things.

        Arguments:

            None.

        Return Value:

            None.

        --*/
        private void ClearRequestForResubmit(bool ntlmFollowupRequest) {
            GlobalLog.ThreadContract(ThreadKinds.Unknown, "HttpWebRequest#" + ValidationHelper.HashString(this) + "::ClearRequestForResubmit");

            // Clear restricted strongly typed headers. See SerializeHeaders().
            // We are not clearing Accept-Encoding because it is not a restricted header.
            _HttpRequestHeaders.RemoveInternal(HttpKnownHeaderNames.Host);
            _HttpRequestHeaders.RemoveInternal(HttpKnownHeaderNames.Connection);
            _HttpRequestHeaders.RemoveInternal(HttpKnownHeaderNames.ProxyConnection);
            _HttpRequestHeaders.RemoveInternal(HttpKnownHeaderNames.ContentLength);
            _HttpRequestHeaders.RemoveInternal(HttpKnownHeaderNames.TransferEncoding);
            _HttpRequestHeaders.RemoveInternal(HttpKnownHeaderNames.Expect);

            if (_HttpResponse != null && _HttpResponse.ResponseStream != null) {
                //
                // We just drain the response data, and throw them away since we're redirecting or authenticating.
                //
                GlobalLog.Print("HttpWebRequest#" + ValidationHelper.HashString(this) + "::ClearRequestForResubmit() draining ResponseStream");
                if (!_HttpResponse.KeepAlive) {
                    ConnectStream liveStream = _HttpResponse.ResponseStream as ConnectStream;
                    if (liveStream != null ) {
                        // The response stream may be closed at any time by the server.
                        // At this point we don't want to drain such a ConnectStream.
                        liveStream.ErrorResponseNotify(false);
                    }
                }
                ICloseEx icloseEx = _HttpResponse.ResponseStream as ICloseEx;
                if (icloseEx != null) {
                    icloseEx.CloseEx(CloseExState.Silent);
                }
                else {
                    _HttpResponse.ResponseStream.Close();
                }
            }

            _AbortDelegate = null;

            m_BodyStarted = false;
            HeadersCompleted = false;
            _WriteBuffer = null;
            m_Extra401Retry = false;

#if TRAVE
            _OldResponse = _HttpResponse;
#endif
            HttpWebResponse priorResponse = _HttpResponse;
            _HttpResponse = null;

            m_ContinueGate.Reset();
            _RerequestCount += 1;

            if (!Aborted && Async)
                _CoreResponse = null;

            if (_SubmitWriteStream != null) {
                //
                // We're uploading and need to resubmit for Authentication or Redirect.
                // if the response wants to keep alive the connection we shouldn't be closing
                // it (this would also brake connection-oriented authentication schemes such as NTLM).
                // so we need to flush all the data to the wire.
                // if the server is closing the connection, instead, we can just close our side as well.
                if ((priorResponse != null && priorResponse.KeepAlive) || _SubmitWriteStream.IgnoreSocketErrors)
                {
                    //
                    // the server wants to keep the connection alive.
                    // if we're uploading data, we need to make sure that we upload all
                    // of it before we start resubmitting.
                    // give the stream to the user if he didn't get it yet.
                    // if the user has set ContentLength to a big number, then we might be able
                    // to just decide to close the connection, but we need to be careful to NTLM.
                    //
                    GlobalLog.Assert(HttpWriteMode != HttpWriteMode.Unknown, "HttpWebRequest#{0}::ClearRequestForResubmit()|HttpWriteMode:{1}", ValidationHelper.HashString(this), HttpWriteMode);
                    if (HasEntityBody)
                    {
                        //
                        // we're uploading
                        //
                        GlobalLog.Print("HttpWebRequest#" + ValidationHelper.HashString(this) + "::ClearRequestForResubmit() _WriteAResult:" + ValidationHelper.ToString(_WriteAResult));

                        //
                        // the user didn't get the stream yet, give it to him
                        //
                        GlobalLog.Print("HttpWebRequest#" + ValidationHelper.HashString(this) + "::ClearRequestForResubmit() calling SetRequestContinue()");

                        if (AllowWriteStreamBuffering) {
                            SetRequestContinue();
                        }

                        // The second NTLM request is required to use the same connection, don't close it
                        if (ntlmFollowupRequest) {
                            // We only want CallDone to do a [....] read now if 100Continue won't later
                            NeedsToReadForResponse = !ShouldWaitFor100Continue();
                            _SubmitWriteStream.CallDone();
                        }
                        else if (!AllowWriteStreamBuffering) {
                            // We only want CloseInternal to do a [....] read now if 100Continue won't later
                            NeedsToReadForResponse = !ShouldWaitFor100Continue();
                            _SubmitWriteStream.CloseInternal(true);
                        }
                        else if (!Async && UserRetrievedWriteStream) {
                            _SubmitWriteStream.CallDone();
                        }
                    }
                }

                if ((Async || UserRetrievedWriteStream) && _OldSubmitWriteStream != null && _OldSubmitWriteStream != _SubmitWriteStream) {
                    GlobalLog.Print("HttpWebRequest#" + ValidationHelper.HashString(this) + "::ClearRequestForResubmit() closing RequestStream");
                    _SubmitWriteStream.CloseInternal(true);
                }
            }
        }
        // If abortState becomes non-zero, the attempt to find a service point has been aborted.
        internal static ServicePoint FindServicePoint(Uri address, IWebProxy proxy, out ProxyChain chain, ref HttpAbortDelegate abortDelegate, ref int abortState)
        {
            if (address==null) {
                throw new ArgumentNullException("address");
            }
            GlobalLog.Enter("ServicePointManager::FindServicePoint() address:" + address.ToString());

            bool isProxyServicePoint = false;
            chain = null;

            //
            // find proxy info, and then switch on proxy
            //
            Uri proxyAddress = null;
            if (proxy!=null  && !address.IsLoopback) {
                IAutoWebProxy autoProxy = proxy as IAutoWebProxy;
                if (autoProxy != null)
                {
                    chain = autoProxy.GetProxies(address);

                    // Set up our ability to abort this MoveNext call.  Note that the current implementations of ProxyChain will only
                    // take time on the first call, so this is the only place we do this.  If a new ProxyChain takes time in later
                    // calls, this logic should be copied to other places MoveNext is called.
                    GlobalLog.Assert(abortDelegate == null, "ServicePointManager::FindServicePoint()|AbortDelegate already set.");
                    abortDelegate = chain.HttpAbortDelegate;
                    try
                    {
                        Thread.MemoryBarrier();
                        if (abortState != 0)
                        {
                            Exception exception = new WebException(NetRes.GetWebStatusString(WebExceptionStatus.RequestCanceled), WebExceptionStatus.RequestCanceled);
                            GlobalLog.LeaveException("ServicePointManager::FindServicePoint() Request aborted before proxy lookup.", exception);
                            throw exception;
                        }

                        if (!chain.Enumerator.MoveNext())
                        {
                            GlobalLog.Assert("ServicePointManager::FindServicePoint()|GetProxies() returned zero proxies.");
/*
                            Exception exception = new WebException(NetRes.GetWebStatusString(WebExceptionStatus.RequestProhibitedByProxy), WebExceptionStatus.RequestProhibitedByProxy);
                            GlobalLog.LeaveException("ServicePointManager::FindServicePoint() Proxy prevented request.", exception);
                            throw exception;
*/
                        }
                        proxyAddress = chain.Enumerator.Current;
                    }
                    finally
                    {
                        abortDelegate = null;
                    }
                }
                else if (!proxy.IsBypassed(address))
                {
                    // use proxy support
                    // rework address
                    proxyAddress = proxy.GetProxy(address);
                }

                // null means DIRECT
                if (proxyAddress!=null) {
                    address = proxyAddress;
                    isProxyServicePoint = true;
                }
            }

            ServicePoint servicePoint = FindServicePointHelper(address, isProxyServicePoint);
            GlobalLog.Leave("ServicePointManager::FindServicePoint() servicePoint#" + ValidationHelper.HashString(servicePoint));
            return servicePoint;
        }
Beispiel #17
0
        /*
            Abort - Attempts to abort pending request,

            This calls into the delegate, and then closes any pending streams.

            Input: none

            Returns: none

        */
        /// <include file='doc\HttpWebRequest.uex' path='docs/doc[@for="HttpWebRequest.Abort"]/*' />
        public override void Abort()
        {
            _OnceFailed = true;
            _Abort = true;

            GlobalLog.Print("HttpWebRequest#" + ValidationHelper.HashString(this) + "::Abort()");

            _ResponseException = new WebException(
                    NetRes.GetWebStatusString("net_requestaborted", WebExceptionStatus.RequestCanceled),
                    WebExceptionStatus.RequestCanceled) ;

            _HaveResponse = true;

            try {
                if ( _AbortDelegate != null ) {
                    _AbortDelegate();
                    _AbortDelegate = null;
                }
            }
            catch {
            }

            try {
                if (_SubmitWriteStream != null) {
                    _SubmitWriteStream.CloseInternal(true);
                    _SubmitWriteStream = null;
                }
            }
            catch {
            }

            try {
                if (_HttpResponse != null) {
                    _HttpResponse.Close();
                }
            }
            catch {
            }
        }
Beispiel #18
0
        /*++

        Routine Description:

            Wakes up blocked threads, so they can read response object,
              from the result

            We also handle the continuation/termination of a BeginGetResponse,
            by saving out the result and calling its callback if needed.

        Arguments:

            coreData - Contains the data used to create the Response object
            exception - true if we're allowed to throw an exception on error

        Return Value:

            none

        --*/
        internal void SetResponse(CoreResponseData coreResponseData) {
            GlobalLog.Enter("HttpWebRequest#" + ValidationHelper.HashString(this) + "::SetResponse", "*** SETRESP ***");

            //
            // Since we are no longer attached to this Connection,
            // we null out our abort delegate.
            //

            _AbortDelegate = null;

            try {
                if (coreResponseData != null) {
                    _HttpResponse = new HttpWebResponse(_Uri, _Verb, coreResponseData, _MediaType, UsesProxySemantics);
                    coreResponseData = null;
                }
                else {

                    //
                    // not sure how this would happen, but we should not throw an exception,
                    //  which we were earlier doing.
                    //

                    GlobalLog.Assert(false,
                                 "coreResponseData == null",
                                 "");


                    GlobalLog.Leave("HttpWebRequest#" + ValidationHelper.HashString(this) + "::SetResponse", "ASSERT");
                    return;
                }

                //
                // give apps the chance to examine the headers of the new response
                //

                if (_CookieContainer != null) {
                    CookieModule.OnReceivedHeaders(this);
                }

                // New Response

                HttpProcessingResult httpResult = HttpProcessingResult.Continue;

                // handle redirects, authentication, and such
                httpResult = DoSubmitRequestProcessing();

                if (httpResult == HttpProcessingResult.Continue) {
                    //
                    // Now grab crit sec here, before returning,
                    //  this is to prevent some one from reading
                    //  ReadAResult it as null before we finish
                    //  processing our response
                    //

                    LazyAsyncResult asyncResult = null;
                    lock(this)
                    {
                        asyncResult = _ReadAResult;

                        GlobalLog.Assert(asyncResult == null || this == (HttpWebRequest)asyncResult.AsyncObject,
                                     "SetResponse: this != asyncResult.AsyncObject",
                                     "");

                        GlobalLog.Assert(asyncResult == null || !asyncResult.IsCompleted, "SetResponse: asyncResult already completed!", "");

                        _HaveResponse = true;

                        if (asyncResult != null) {
                            _ReadAResult = null;
                        }
                    }

                    if (asyncResult != null) {
                        asyncResult.InvokeCallback(false, _HttpResponse);
                    }

                    if ( _WriteEvent != null ) {
                        GlobalLog.Print("HttpWebRequest#" + ValidationHelper.HashString(this) + "::SetResponse(CoreResponseData) calling _WriteEvent.Set()");
                        _WriteEvent.Set();
                    }
                }
            } catch (Exception exception) {
                Abort();
                GlobalLog.LeaveException("HttpWebRequest#" + ValidationHelper.HashString(this) + "::SetResponse", exception);
                throw;
            }

            if (_Abort) {
                try {
                    if ( _HttpResponse != null ) {
                        _HttpResponse.Close();
                    }
                }
                catch {
                }

                GlobalLog.Leave("HttpWebRequest#" + ValidationHelper.HashString(this) + "::SetResponse", "ABORT");
                return;
            }

            GlobalLog.Leave("HttpWebRequest#" + ValidationHelper.HashString(this) + "::SetResponse");
        }
Beispiel #19
0
        /*++

        Routine Description:

            Wakes up blocked threads, so they can throw exceptions.

        Arguments:

            None.

        Return Value:

            HttpWebResponse

        --*/
        internal void SetResponse(Exception E) {
            GlobalLog.Enter("HttpWebRequest#" + ValidationHelper.HashString(this) + "::SetResponse", E.ToString() + "/*** SETRESPONSE IN ERROR ***");

            //
            // Since we are no longer attached to this Connection,
            // we null out our abort delegate.
            //
            _AbortDelegate = null;

            if ( _WriteEvent != null ) {
                GlobalLog.Print("HttpWebRequest#" + ValidationHelper.HashString(this) + "::SetResponse(Exception) calling _WriteEvent.Set()");
                _WriteEvent.Set();
            }

            if ((E as WebException) == null) {
                if (_HttpResponse==null) {
                    E = new WebException(E.Message, E);
                }
                else {
                    E = new WebException(
                        SR.GetString(
                            SR.net_servererror,
                            NetRes.GetWebStatusCodeString(
                                ResponseStatusCode,
                                _HttpResponse.StatusDescription)),
                        E,
                        WebExceptionStatus.ProtocolError,
                        _HttpResponse );
                }
            }

            _ResponseException = E;

            // grab crit sec to protect BeginGetResponse/EndGetResponse code path
            Monitor.Enter(this);

            _HaveResponse = true;

            LazyAsyncResult writeAsyncResult = _WriteAResult;
            LazyAsyncResult readAsyncResult = _ReadAResult;

            _WriteAResult = null;
            _ReadAResult = null;

            Monitor.Exit(this);

            if (writeAsyncResult != null) {
                writeAsyncResult.InvokeCallback(false);
            }
            if (readAsyncResult != null) {
                readAsyncResult.InvokeCallback(false);
            }

            GlobalLog.Leave("HttpWebRequest#" + ValidationHelper.HashString(this) + "::SetResponse");
        }
 internal static ServicePoint FindServicePoint(Uri address, IWebProxy proxy, out ProxyChain chain, ref HttpAbortDelegate abortDelegate, ref int abortState)
 {
     if (address == null)
     {
         throw new ArgumentNullException("address");
     }
     bool isProxyServicePoint = false;
     chain = null;
     Uri current = null;
     if ((proxy != null) && !address.IsLoopback)
     {
         IAutoWebProxy proxy2 = proxy as IAutoWebProxy;
         if (proxy2 != null)
         {
             chain = proxy2.GetProxies(address);
             abortDelegate = chain.HttpAbortDelegate;
             try
             {
                 Thread.MemoryBarrier();
                 if (abortState != 0)
                 {
                     Exception exception = new WebException(NetRes.GetWebStatusString(WebExceptionStatus.RequestCanceled), WebExceptionStatus.RequestCanceled);
                     throw exception;
                 }
                 chain.Enumerator.MoveNext();
                 current = chain.Enumerator.Current;
             }
             finally
             {
                 abortDelegate = null;
             }
         }
         else if (!proxy.IsBypassed(address))
         {
             current = proxy.GetProxy(address);
         }
         if (current != null)
         {
             address = current;
             isProxyServicePoint = true;
         }
     }
     return FindServicePointHelper(address, isProxyServicePoint);
 }
Beispiel #21
0
        /*++

            BeginSubmitRequest: Begins Submit off a request to the network.

            This is called when we need to transmit an Async Request, but
            this function only servers to activate the submit, and does not
            actually block

            Called when we want to submit a request to the network. We do several
            things here - look for a proxy, find the service point, etc. In the
            end we call the service point to get access (via a stream) to the
            underlying connection, then serialize our headers onto that connection.
            The actual submission request to the service point is async, so we
            submit the request and then return, to allow the async to run its course.

            Input:
                forceFind - insures that always get a new ServicePoint,
                    needed on redirects, or where the ServicePoint may have changed

            Returns: Nothing

        --*/

        internal void BeginSubmitRequest(bool forceFind) {
            GlobalLog.Enter("HttpWebRequest#" + ValidationHelper.HashString(this) + "::BeginSubmitRequest", forceFind.ToString());
            GlobalLog.Print("HttpWebRequest#" + ValidationHelper.HashString(this) + " " + Method + " " + Address);


            if (_SubmitWriteStream!=null) {
                long writeBytes = _SubmitWriteStream.BytesLeftToWrite;

                GlobalLog.Print("HttpWebRequest#" + ValidationHelper.HashString(this) + "::BeginSubmitRequest() _OldSubmitWriteStream:" + ValidationHelper.HashString(_OldSubmitWriteStream) + " _SubmitWriteStream:" + ValidationHelper.HashString(_SubmitWriteStream) + " writeBytes:" + writeBytes.ToString());

                if (writeBytes == 0) {
                    //
                    // we're resubmitting a request with an entity body
                    //
                    _OldSubmitWriteStream = _SubmitWriteStream;
                    if (_SubmitWriteStream.BufferedData!=null && _SubmitWriteStream.BufferedData.Length>0) {
                        //
                        // if we're resubmitting and buffering:
                        //
                        SetContentLength(_SubmitWriteStream.BufferedData.Length);
                        WriteBuffer = null;
                    }
                }
                else {
                    GlobalLog.Print("HttpWebRequest#" + ValidationHelper.HashString(this) + "::BeginSubmitRequest() got a _SubmitWriteStream.WriteBytes:" + writeBytes.ToString());
                }
            }

            GlobalLog.Print("HttpWebRequest#" + ValidationHelper.HashString(this) + "::BeginSubmitRequest() _HaveResponse:" + _HaveResponse.ToString());
            GlobalLog.Print("HttpWebRequest#" + ValidationHelper.HashString(this) + "::BeginSubmitRequest() _RequestSubmitted:" + _RequestSubmitted.ToString());
            GlobalLog.Print("HttpWebRequest#" + ValidationHelper.HashString(this) + "::BeginSubmitRequest() Saw100Continue:" + Saw100Continue.ToString());

            // if we're submitting then we don't have a response
            _HaveResponse = false;
            _RequestSubmitted = true;

            ServicePoint servicePoint = FindServicePoint(forceFind);

            if ((_HttpWriteMode != HttpWriteMode.None) && (_WriteEvent == null)) {
                // don't create a WriteEvent until we are doing a Write
                GlobalLog.Print("HttpWebRequest#" + ValidationHelper.HashString(this) + "::BeginSubmitRequest() lazy allocation of _WriteEvent");
                _WriteEvent = new AutoResetEvent(false);
            }

            _AbortDelegate = servicePoint.SubmitRequest(this, GetConnectionGroupLine());

            // prevent someone from sending chunked to a HTTP/1.0 server
            if (ChunkedUploadOnHttp10) {
                Abort();
                throw new ProtocolViolationException(SR.GetString(SR.net_nochunkuploadonhttp10));
            }

            GlobalLog.Leave("HttpWebRequest#" + ValidationHelper.HashString(this) + "::BeginSubmitRequest");
        }