VirtualBox

Changeset 43713 in vbox for trunk/src/VBox/Runtime/common


Ignore:
Timestamp:
Oct 23, 2012 3:11:35 PM (12 years ago)
Author:
vboxsync
Message:

iprt/http: added support for custom headers

File:
1 edited

Legend:

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

    r43679 r43713  
    4848    CURL *pCurl;
    4949    long lLastResp;
     50    struct curl_slist *pHeaders;
    5051} RTHTTPINTERNAL;
    5152typedef RTHTTPINTERNAL *PRTHTTPINTERNAL;
     
    116117
    117118    curl_easy_cleanup(pHttpInt->pCurl);
     119       
     120    if (pHttpInt->pHeaders)
     121        curl_slist_free_all(pHttpInt->pHeaders);
    118122
    119123    RTMemFree(pHttpInt);
     
    169173}
    170174
     175RTR3DECL(int) RTHttpSetHeaders(RTHTTP hHttp, uint32_t cHeaders, const char *pcszHeaders[])
     176{
     177    PRTHTTPINTERNAL pHttpInt = hHttp;
     178    RTHTTP_VALID_RETURN(pHttpInt);
     179
     180    if (!cHeaders)
     181    {
     182        if (pHttpInt->pHeaders)
     183            curl_slist_free_all(pHttpInt->pHeaders);
     184        pHttpInt->pHeaders = 0;
     185        return VINF_SUCCESS;
     186    }
     187
     188    struct curl_slist* pHeaders = NULL;
     189    for (unsigned i = 0; i < cHeaders; i++)
     190        pHeaders = curl_slist_append(pHeaders, pcszHeaders[i]);
     191
     192    pHttpInt->pHeaders = pHeaders;
     193    int rcCurl = curl_easy_setopt(pHttpInt->pCurl, CURLOPT_HTTPHEADER, pHeaders);
     194    if (CURL_FAILED(rcCurl))
     195        return VERR_INVALID_PARAMETER;
     196
     197    return VINF_SUCCESS;
     198}
     199
    171200RTR3DECL(int) RTHttpGet(RTHTTP hHttp, const char *pcszUrl, char **ppszResponse)
    172201{
     
    177206    if (CURL_FAILED(rcCurl))
    178207        return VERR_INVALID_PARAMETER;
     208
     209#if 0
     210    rcCurl = curl_easy_setopt(pHttpInt->pCurl, CURLOPT_VERBOSE, 1);
     211    if (CURL_FAILED(rcCurl))
     212        return VERR_INVALID_PARAMETER;
     213#endif
    179214
    180215    /* XXX */
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