| 2695 | } |
| 2696 | |
| 2697 | void WebRequestCURL::DoStartPrepare(StringView url) |
| 2698 | { |
| 2699 | DEATH_ASSERT(_handle != nullptr, "libcurl initialization failed", ); |
| 2700 | |
| 2701 | // Set error buffer to get more detailed CURL status |
| 2702 | _errorBuffer[0] = '\0'; |
| 2703 | CURLSetOpt(_handle, CURLOPT_ERRORBUFFER, _errorBuffer); |
| 2704 | CURLSetOpt(_handle, CURLOPT_URL, url); |
| 2705 | |
| 2706 | // Set callback functions |
| 2707 | CURLSetOpt(_handle, CURLOPT_WRITEFUNCTION, CURLWriteData); |
| 2708 | CURLSetOpt(_handle, CURLOPT_HEADERFUNCTION, CURLHeader); |
| 2709 | CURLSetOpt(_handle, CURLOPT_READFUNCTION, CURLRead); |
| 2710 | CURLSetOpt(_handle, CURLOPT_READDATA, this); |
| 2711 | CURLSetOpt(_handle, CURLOPT_ACCEPT_ENCODING, ""); |
| 2712 | // Enable redirection handling |
| 2713 | CURLSetOpt(_handle, CURLOPT_FOLLOWLOCATION, 1L); |
| 2714 | // Limit redirect to HTTP |
| 2715 | # if CURL_AT_LEAST_VERSION(7, 85, 0) |
| 2716 | if (WebSessionCURL::CurlRuntimeAtLeastVersion(7, 85, 0)) { |
| 2717 | CURLSetOpt(_handle, CURLOPT_REDIR_PROTOCOLS_STR, "http,https"); |
| 2718 | } else |
| 2719 | # endif |
| 2720 | { |
| 2721 | DEATH_IGNORE_DEPRECATED_PUSH |
| 2722 | CURLSetOpt(_handle, CURLOPT_REDIR_PROTOCOLS, CURLPROTO_HTTP | CURLPROTO_HTTPS); |
| 2723 | DEATH_IGNORE_DEPRECATED_POP |
| 2724 | } |
| 2725 | |
| 2726 | const WebProxy& proxy = GetSessionImpl().GetProxy(); |
| 2727 | bool usingProxy = true; |
| 2728 | switch (proxy.GetType()) { |
| 2729 | case WebProxy::Type::URL: |
| 2730 | CURLSetOpt(_handle, CURLOPT_PROXY, proxy.GetURL()); |
| 2731 | break; |
| 2732 | |
| 2733 | case WebProxy::Type::Disabled: |
| 2734 | // This is a special value disabling use of proxy |
| 2735 | CURLSetOpt(_handle, CURLOPT_PROXY, ""); |
| 2736 | usingProxy = false; |
| 2737 | break; |
| 2738 | |
| 2739 | case WebProxy::Type::Default: |
| 2740 | // Nothing to do, libcurl will use the standard http_proxy and other similar environment variables by default |
| 2741 | break; |
| 2742 | } |
| 2743 | |
| 2744 | // Enable all supported authentication methods |
| 2745 | CURLSetOpt(_handle, CURLOPT_HTTPAUTH, CURLAUTH_ANY); |
| 2746 | if (usingProxy) { |
| 2747 | CURLSetOpt(_handle, CURLOPT_PROXYAUTH, CURLAUTH_ANY); |
| 2748 | } |
| 2749 | } |
| 2750 | |
| 2751 | WebRequestCURL::~WebRequestCURL() |
| 2752 | { |
nothing calls this directly
no test coverage detected