VirtualBox

Ignore:
Timestamp:
Jul 23, 2018 4:52:04 PM (6 years ago)
Author:
vboxsync
Message:

IPRT: Added RTHttpSetFollowRedirects (translates to CURLOPT_FOLLOWLOCATION+CURLOPT_MAXREDIRS) and make use of it RTDbgCfg and RTHttp[.exe]. This should fix the current pdb download issues as we're getting 302 redirects from the servers. Also, changed RTHttp to return VERR_HTTP_REDIRECTED when receiving 302, 303, 307 & 308 HTTP statuses.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Runtime/generic/http-curl.cpp

    r70141 r73334  
    126126    /** @} */
    127127
     128    /** @name Cached settings.
     129     * @{ */
     130    /** Maximum number of redirects to follow.
     131     * Zero if not automatically following (default). */
     132    uint32_t            cMaxRedirects;
     133    /** @} */
     134
    128135    /** Abort the current HTTP request if true. */
    129136    bool volatile       fAbort;
     
    273280                pThis->pCurl                    = pCurl;
    274281                pThis->fUseSystemProxySettings  = true;
     282                pThis->cMaxRedirects            = 0; /* no automatic redir following */
    275283
    276284                *phHttp = (RTHTTP)pThis;
     
    18251833
    18261834
     1835RTR3DECL(int) RTHttpSetFollowRedirects(RTHTTP hHttp, uint32_t cMaxRedirects)
     1836{
     1837    PRTHTTPINTERNAL pThis = hHttp;
     1838    RTHTTP_VALID_RETURN(pThis);
     1839    AssertReturn(!pThis->fBusy, VERR_WRONG_ORDER);
     1840
     1841    /*
     1842     * Update the redirection settings.
     1843     */
     1844    if (pThis->cMaxRedirects != cMaxRedirects)
     1845    {
     1846        int rcCurl = curl_easy_setopt(pThis->pCurl, CURLOPT_MAXREDIRS, (long)cMaxRedirects);
     1847        AssertMsgReturn(rcCurl == CURLE_OK, ("CURLOPT_MAXREDIRS=%u: %d (%#x)\n", cMaxRedirects, rcCurl, rcCurl),
     1848                        VERR_HTTP_CURL_ERROR);
     1849
     1850        rcCurl = curl_easy_setopt(pThis->pCurl, CURLOPT_FOLLOWLOCATION, (long)(cMaxRedirects > 0));
     1851        AssertMsgReturn(rcCurl == CURLE_OK, ("CURLOPT_FOLLOWLOCATION=%d: %d (%#x)\n", cMaxRedirects > 0, rcCurl, rcCurl),
     1852                        VERR_HTTP_CURL_ERROR);
     1853
     1854        pThis->cMaxRedirects = cMaxRedirects;
     1855    }
     1856    return VINF_SUCCESS;
     1857}
     1858
     1859
    18271860RTR3DECL(int) RTHttpSetHeaders(RTHTTP hHttp, size_t cHeaders, const char * const *papszHeaders)
    18281861{
     
    20492082                rc = VINF_SUCCESS;
    20502083                break;
    2051             case 301:
     2084            case 301: /* Moved permantently. */
     2085            case 302: /* Found / Moved temporarily. */
     2086            case 303: /* See Other. */
     2087            case 307: /* Temporary redirect. */
     2088            case 308: /* Permanent redirect. */
    20522089            {
    2053                 const char *pszRedirect;
     2090                const char *pszRedirect = NULL;
    20542091                curl_easy_getinfo(pThis->pCurl, CURLINFO_REDIRECT_URL, &pszRedirect);
    2055                 size_t cb = strlen(pszRedirect);
     2092                size_t cb = pszRedirect ? strlen(pszRedirect) : 0;
    20562093                if (cb > 0 && cb < 2048)
    20572094                    pThis->pszRedirLocation = RTStrDup(pszRedirect);
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette