VirtualBox

Ignore:
Timestamp:
Sep 13, 2018 4:33:17 PM (6 years ago)
Author:
vboxsync
Message:

IRPT/rest,http: Use header callbacks for capturing header values in responses. Removed [P]FNCREATEINSTANCE as it isn't needed any more (and it didn't work like expected for RTCRestString). Some HTTP header callback updates. bugref:9167

File:
1 edited

Legend:

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

    r74222 r74250  
    30413041    if (pThis->pfnHeaderCallback)
    30423042    {
    3043         /* Find the end of the field name first.  Since cURL gives us the
    3044            "HTTP/{version} {code} {status}" line too, we slap a fictitious
    3045            field name ':http-status-line' in front of it. */
     3043        /*
     3044         * Find the end of the field name first.
     3045         */
    30463046        uint32_t    uMatchWord;
    30473047        size_t      cchField;
     
    30633063            cchValue = cbToAppend - cchField - 1;
    30643064        }
    3065         else if (pchBuf[0] == 'H' && pchBuf[1] == 'T' && pchBuf[2] == 'T' && pchBuf[1] == 'P')
     3065        /* Since cURL gives us the "HTTP/{version} {code} {status}" line too,
     3066           we slap a fictitious field name ':http-status-line' in front of it. */
     3067        else if (cbToAppend > 5 && pchBuf[0] == 'H' && pchBuf[1] == 'T' && pchBuf[2] == 'T' && pchBuf[3] == 'P' && pchBuf[4] == '/')
    30663068        {
    30673069            pchField   = ":http-status-line";
     
    30713073            cchValue   = cbToAppend;
    30723074        }
     3075        /* cURL also gives us the empty line before the body, so we slap another
     3076           fictitious field name ':end-of-headers' in front of it as well. */
     3077        else if (cbToAppend == 2 && pchBuf[0] == '\r' && pchBuf[1] == '\n')
     3078        {
     3079            pchField   = ":end-of-headers";
     3080            cchField   = 15;
     3081            uMatchWord = RTHTTP_MAKE_HDR_MATCH_WORD(15, ':', 'e', 'n');
     3082            pchValue   = pchBuf;
     3083            cchValue   = cbToAppend;
     3084        }
    30733085        else
    30743086            AssertMsgFailedReturn(("pchBuf=%.*s\n", cbToAppend, pchBuf), cbToAppend);
    30753087
    3076         /* Determin the field value, stripping one leading blank and all
    3077            trailing spaces. */
     3088        /*
     3089         * Determin the field value, stripping one leading blank and all
     3090         * trailing spaces.
     3091         */
    30783092        if (cchValue > 0 && RT_C_IS_BLANK(*pchValue))
    30793093            pchValue++, cchValue--;
     
    30813095            cchValue--;
    30823096
    3083         /* Pass it to the callback. */
     3097        /*
     3098         * Pass it to the callback.
     3099         */
     3100        Log6(("rtHttpWriteHeaderData: %.*s: %.*s\n", cchField, pchBuf, cchValue, pchValue));
    30843101        int rc = pThis->pfnHeaderCallback(pThis, uMatchWord, pchBuf, cchField,
    30853102                                          pchValue, cchValue, pThis->pvHeaderCallbackUser);
     
    30873104            return cbToAppend;
    30883105
     3106        /* Abort on error. */
    30893107        if (RT_SUCCESS(pThis->rcOutput))
    30903108            pThis->rcOutput = rc;
     
    35473565
    35483566        /* Headers. */
    3549         if (ppvHeaders && CURL_SUCCESS(rcCurl))
     3567        if (CURL_SUCCESS(rcCurl))
    35503568        {
    35513569            RT_ZERO(pThis->HeadersOutput.uData.Mem);
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