Domanda

I am using the CFNetwork to read through the headers and I am trying to read what type of "Transfer-Encoding" my request is. It should be "chunked" Wireshark shows the correct request of "Transfer-Encoding: chunked", but the actually code using CFNetwork redas the request header as "Transfer-Encoding: Identity"

Does anybody know why this is occurring?

Here is my code that reads the headers:

if (r->_headers) {
        CFStringRef header_return = CFStringCreateWithFormat (kCFAllocatorDefault, NULL, CFSTR("%@: %@\r\n"), key, value);
        if (header_return) {            
            char temp[256];
            CFStringGetCString(header_return, temp, sizeof(temp), kCFStringEncodingUTF8);

            char *trans_enc = NULL;
            if (pico_http_internal_native_header_get(temp, "Transfer-Encoding:", &trans_enc)) {
                if (strcmp(trans_enc, "chunked") == 0) {  // <-- This always says "Identity"
                    r->_chunked = true; // Never hit, but wireshark shows it would  be correct
                }
            }

            r->_headers(r->_context, temp, strlen(temp));
            pico_cfrelease(header_return);
        }
    }

Thanks in advance for any help.

È stato utile?

Soluzione

I used the following logic to determine if it was chunked or not:

// response header info
    if(CFHTTPMessageIsHeaderComplete(cf_response)) {
        CFDictionaryRef headers = CFHTTPMessageCopyAllHeaderFields(cf_response);
        if (headers) {
            CFDictionaryApplyFunction(headers, pico_http_internal_cfnetwork_header_apply_callback, r);
            if((CFDictionaryContainsKey(headers, CFSTR("Content-Length")) == false) && (CFDictionaryContainsKey(headers, CFSTR("Transfer-Encoding")) == true)
               && (CFDictionaryContainsValue(headers, CFSTR("Keep-Alive")) == true)) {
                r->_chunked = true;
                }
     }

Basically if there is no "Content-Length" in the headers, but the header reports "Transfer-Encoding", and "Keep-Alive" is reported then it's a chunked response. These are the main differences between a chunked response and a non chunked response. Chunked responses don't use the "Content-Length" but have "Transfer-Encoding" and "Keep-Alive" set.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top