VirtualBox

Ignore:
Timestamp:
Jun 24, 2014 11:06:52 AM (10 years ago)
Author:
vboxsync
Message:

Runtime/http: added handling for 301 responses

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Runtime/common/misc/http.cpp

    r51635 r51704  
    5050typedef struct RTHTTPINTERNAL
    5151{
    52     /** magic value */
    53     uint32_t u32Magic;
    54     /** cURL handle */
    55     CURL *pCurl;
    56     long lLastResp;
     52    /** Magic value. */
     53    uint32_t            u32Magic;
     54    /** cURL handle. */
     55    CURL                *pCurl;
     56    /** The last response code. */
     57    long                lLastResp;
    5758    /** custom headers */
    58     struct curl_slist *pHeaders;
    59     /** CA certificate for HTTPS authentication check */
    60     char *pcszCAFile;
    61     /** abort the current HTTP request if true */
    62     bool fAbort;
     59    struct curl_slist   *pHeaders;
     60    /** CA certificate for HTTPS authentication check. */
     61    char                *pcszCAFile;
     62    /** Abort the current HTTP request if true. */
     63    bool                fAbort;
     64    /** The location field for 301 responses. */
     65    char                *pszRedirLocation;
    6366} RTHTTPINTERNAL;
    6467typedef RTHTTPINTERNAL *PRTHTTPINTERNAL;
     
    136139        RTStrFree(pHttpInt->pcszCAFile);
    137140
     141    if (pHttpInt->pszRedirLocation)
     142        RTStrFree(pHttpInt->pszRedirLocation);
     143
    138144    RTMemFree(pHttpInt);
    139145
     
    172178    pHttpInt->fAbort = true;
    173179
     180    return VINF_SUCCESS;
     181}
     182
     183RTR3DECL(int) RTHttpGetRedirLocation(RTHTTP hHttp, char **ppszRedirLocation)
     184{
     185    PRTHTTPINTERNAL pHttpInt = hHttp;
     186    RTHTTP_VALID_RETURN(pHttpInt);
     187
     188    if (!pHttpInt->pszRedirLocation)
     189        return VERR_HTTP_NOT_FOUND;
     190
     191    *ppszRedirLocation = RTStrDup(pHttpInt->pszRedirLocation);
    174192    return VINF_SUCCESS;
    175193}
     
    354372{
    355373    int rc = VERR_INTERNAL_ERROR;
     374
     375    if (pHttpInt->pszRedirLocation)
     376    {
     377        RTStrFree(pHttpInt->pszRedirLocation);
     378        pHttpInt->pszRedirLocation = NULL;
     379    }
    356380    if (rcCurl == CURLE_OK)
    357381    {
     
    365389                rc = VINF_SUCCESS;
    366390                break;
     391            case 301:
     392            {
     393                const char *pszRedirect;
     394                curl_easy_getinfo(pHttpInt->pCurl, CURLINFO_REDIRECT_URL, &pszRedirect);
     395                size_t cb = strlen(pszRedirect);
     396                if (cb > 0 && cb < 4096)
     397                    pHttpInt->pszRedirLocation = RTStrDup(pszRedirect);
     398                rc = VERR_HTTP_REDIRECTED;
     399                break;
     400            }
    367401            case 400:
    368402                /* bad request */
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