Example #1
0
        protected internal override Task <HttpResponseMessage> SendAsync(
            HttpRequestMessage request,
            CancellationToken cancellationToken)
        {
            if (request == null)
            {
                throw new ArgumentNullException("request", SR.net_http_handler_norequest);
            }

            if ((request.RequestUri.Scheme != UriSchemeHttp) && (request.RequestUri.Scheme != UriSchemeHttps))
            {
                throw NotImplemented.ByDesignWithMessage(SR.net_http_client_http_baseaddress_required);
            }

            if (request.RequestUri.Scheme == UriSchemeHttps && !s_supportsSSL)
            {
                throw new PlatformNotSupportedException(SR.net_http_unix_https_support_unavailable_libcurl);
            }

            if (request.Headers.TransferEncodingChunked.GetValueOrDefault() && (request.Content == null))
            {
                throw new InvalidOperationException(SR.net_http_chunked_not_allowed_with_empty_content);
            }

            // TODO: Check that SendAsync is not being called again for same request object.
            //       Probably fix is needed in WinHttpHandler as well

            CheckDisposed();
            SetOperationStarted();

            // Do an initial cancellation check to avoid initiating the async operation if
            // cancellation has already been requested.  After this, we'll rely on CancellationToken.Register
            // to notify us of cancellation requests and shut down the operation if possible.
            if (cancellationToken.IsCancellationRequested)
            {
                return(Task.FromCanceled <HttpResponseMessage>(cancellationToken));
            }

            // Create the easy request.  This associates the easy request with this handler and configures
            // it based on the settings configured for the handler.
            var easy = new EasyRequest(this, request, cancellationToken);

            // Submit the easy request to the multi agent.
            if (request.Content != null)
            {
                // If there is request content to be sent, preload the stream
                // and submit the request to the multi agent.  This is separated
                // out into a separate async method to avoid associated overheads
                // in the case where there is no request content stream.
                return(QueueOperationWithRequestContentAsync(easy));
            }
            else
            {
                // Otherwise, just submit the request.
                _agent.Queue(easy);
                return(easy.Task);
            }
        }
Example #2
0
        protected internal override Task <HttpResponseMessage> SendAsync(
            HttpRequestMessage request, CancellationToken cancellationToken)
        {
            if (request == null)
            {
                throw new ArgumentNullException(nameof(request), SR.net_http_handler_norequest);
            }

            if (request.RequestUri.Scheme == UriSchemeHttps)
            {
                if (!s_supportsSSL)
                {
                    throw new PlatformNotSupportedException(SR.Format(SR.net_http_unix_https_support_unavailable_libcurl, CurlVersionDescription));
                }
            }
            else
            {
                Debug.Assert(request.RequestUri.Scheme == UriSchemeHttp, "HttpClient expected to validate scheme as http or https.");
            }

            if (request.Headers.TransferEncodingChunked.GetValueOrDefault() && (request.Content == null))
            {
                throw new InvalidOperationException(SR.net_http_chunked_not_allowed_with_empty_content);
            }

            if (_useCookie && _cookieContainer == null)
            {
                throw new InvalidOperationException(SR.net_http_invalid_cookiecontainer);
            }

            CheckDisposed();
            SetOperationStarted();

            // Do an initial cancellation check to avoid initiating the async operation if
            // cancellation has already been requested.  After this, we'll rely on CancellationToken.Register
            // to notify us of cancellation requests and shut down the operation if possible.
            if (cancellationToken.IsCancellationRequested)
            {
                return(Task.FromCanceled <HttpResponseMessage>(cancellationToken));
            }

            // Create the easy request.  This associates the easy request with this handler and configures
            // it based on the settings configured for the handler.
            var easy = new EasyRequest(this, _agent, request, cancellationToken);

            try
            {
                EventSourceTrace("{0}", request, easy: easy);
                _agent.Queue(new MultiAgent.IncomingRequest {
                    Easy = easy, Type = MultiAgent.IncomingRequestType.New
                });
            }
            catch (Exception exc)
            {
                easy.CleanupAndFailRequest(exc);
            }

            return(easy.Task);
        }
Example #3
0
 private void ConfigureAndQueue(EasyRequest easy)
 {
     try
     {
         easy.InitializeCurl();
         _agent.Queue(new MultiAgent.IncomingRequest {
             Easy = easy, Type = MultiAgent.IncomingRequestType.New
         });
     }
     catch (Exception exc)
     {
         easy.FailRequest(exc);
         easy.Cleanup(); // no active processing remains, so we can cleanup
     }
 }