Пример #1
0
        static async Task <CURLResponse> ProcessHttpResponseTask(Context ctx, CURLResource ch, Task <WebResponse> responseTask)
        {
            try
            {
                using (var response = (HttpWebResponse)responseTask.Result)
                {
                    return(new CURLResponse(await ProcessResponse(ctx, ch, response), response, ch));
                }
            }
            catch (AggregateException agEx)
            {
                var ex = agEx.InnerException;

                ch.VerboseOutput(ex.ToString());

                if (ex is WebException webEx)
                {
                    // TODO: ch.FailOnError ?

                    var exception = webEx.InnerException ?? webEx;

                    switch (webEx.Status)
                    {
                    case WebExceptionStatus.ProtocolError:
                        // actually ok, 301, 500, etc .. process the response:
                        return(new CURLResponse(await ProcessResponse(ctx, ch, (HttpWebResponse)webEx.Response), (HttpWebResponse)webEx.Response, ch));

                    case WebExceptionStatus.Timeout:
                        return(CURLResponse.CreateError(CurlErrors.CURLE_OPERATION_TIMEDOUT, exception));

                    case WebExceptionStatus.TrustFailure:
                        return(CURLResponse.CreateError(CurlErrors.CURLE_SSL_CACERT, exception));

                    default:
                        return(CURLResponse.CreateError(CurlErrors.CURLE_COULDNT_CONNECT, exception));
                    }
                }
                else if (ex is ProtocolViolationException)
                {
                    return(CURLResponse.CreateError(CurlErrors.CURLE_FAILED_INIT, ex));
                }
                else if (ex is CryptographicException)
                {
                    return(CURLResponse.CreateError(CurlErrors.CURLE_SSL_CERTPROBLEM, ex));
                }
                else
                {
                    throw ex;
                }
            }
        }
Пример #2
0
        static CURLResponse ProcessHttpResponseTask(Context ctx, CURLResource ch, Task <WebResponse> responseTask)
        {
            try
            {
                using (var response = (HttpWebResponse)responseTask.Result)
                {
                    return(new CURLResponse(ProcessResponse(ctx, ch, response), response));
                }
            }
            catch (AggregateException agEx)
            {
                var ex = agEx.InnerException;
                if (ex is WebException webEx)
                {
                    switch (webEx.Status)
                    {
                    case WebExceptionStatus.Timeout:
                        return(CURLResponse.CreateError(CurlErrors.CURLE_OPERATION_TIMEDOUT, webEx));

                    case WebExceptionStatus.TrustFailure:
                        return(CURLResponse.CreateError(CurlErrors.CURLE_SSL_CACERT, webEx));

                    default:
                        return(CURLResponse.CreateError(CurlErrors.CURLE_COULDNT_CONNECT, webEx));
                    }
                }
                else if (ex is ProtocolViolationException)
                {
                    return(CURLResponse.CreateError(CurlErrors.CURLE_FAILED_INIT, ex));
                }
                else if (ex is CryptographicException)
                {
                    return(CURLResponse.CreateError(CurlErrors.CURLE_SSL_CERTPROBLEM, ex));
                }
                else
                {
                    throw ex;
                }
            }
        }
Пример #3
0
        static void StartRequestExecution(Context ctx, CURLResource ch)
        {
            ch.StartTime = DateTime.UtcNow;

            var uri = TryCreateUri(ch);

            if (uri == null)
            {
                ch.Result = CURLResponse.CreateError(CurlErrors.CURLE_URL_MALFORMAT);
            }
            else if (
                IsProtocol(ch, uri, "http", CURLConstants.CURLPROTO_HTTP) ||
                IsProtocol(ch, uri, "https", CURLConstants.CURLPROTO_HTTPS))
            {
                ch.Result       = null;
                ch.ResponseTask = ExecHttpRequestInternalAsync(ctx, ch, uri);
            }
            else
            {
                ch.Result = CURLResponse.CreateError(CurlErrors.CURLE_UNSUPPORTED_PROTOCOL);
            }
        }
Пример #4
0
        static void StartRequestExecution(Context ctx, CURLResource ch)
        {
            ch.StartTime = DateTime.UtcNow;

            var uri = TryCreateUri(ch);

            if (uri == null)
            {
                ch.Result = CURLResponse.CreateError(CurlErrors.CURLE_URL_MALFORMAT);
            }
            else if (
                string.Equals(uri.Scheme, "http", StringComparison.OrdinalIgnoreCase) ||
                string.Equals(uri.Scheme, "https", StringComparison.OrdinalIgnoreCase))
            {
                ch.Result       = null;
                ch.ResponseTask = ExecHttpRequestInternalAsync(ctx, ch, uri);
            }
            else
            {
                ch.Result = CURLResponse.CreateError(CurlErrors.CURLE_UNSUPPORTED_PROTOCOL);
            }
        }