Note that there are some explanatory texts on larger screens.

plurals
  1. POMissing chunk size in chunked HTTP response using libcurl
    text
    copied!<p>I tried to use curl library to build a HTTP proxy. The problem I faced now is chunked HTTP response is not correct. By checking the file saved HTTP response, I found that the chunk size at begining and end of HTTP response is missing. The HTTP response got from curl callback function as show below. </p> <pre><code>size_t httpClient::write_data(char *ptr, size_t size, size_t nmemb, void* userdata) { // get total size size_t realsize = size*nmemb; // get object struct MemoryStruct* mem = (struct MemoryStruct*)userdata; // size of memory block pointerd by the mem-&gt;memory is changed to the new bytes mem-&gt;memory = (char*)realloc(mem-&gt;memory, (mem-&gt;size + realsize)); if(mem-&gt;memory == NULL) { printf("not enough memory (realloc returned NULL)\n"); exit(1); } // copy to memory structure memcpy(&amp;(mem-&gt;memory[mem-&gt;size]), ptr, realsize); mem-&gt;size += realsize; //mem-&gt;memory[mem-&gt;size] = 0; cout&lt;&lt;"Write ["&lt;&lt;realsize&lt;&lt;"] bytes Data to chunk"&lt;&lt;endl; return realsize; } </code></pre> <p>Hope someone can point out the mistake I made for this callback function. Thanks :D</p> <p>The expected chunked HTTP response is shown below:</p> <pre><code>HTTP/1.1 200 OK^M Date: Wed, 17 Oct 2012 07:44:54 GMT^M Expires: -1^M Cache-Control: private, max-age=0^M Content-Type: text/html; charset=UTF-8^M Set-Cookie: PREF=ID=58da9f2271ea2d2b:FF=0:TM=1350459894:LM=1350459894:S=EnJS1hQo2d6_AnPM; expires=Fri, 17-Oct-2014 07:44:54 GMT; path=/; domain=.google.com^M Set-Cookie: NID=65=RW0txpQSNA4NwlRhp0y1I6iF3L0xfugw8Bv4GMsB1yE1qu7iGoBO_2ZxqS0-DSeS4tJKnV26JlfVZmsnjxnjdUaHTDj3-AFREsvyMiE8wSKyabwYG8x-e18Pj8smdxUs; expires=Thu, 18-Apr-2013 07:44:54 GMT; path=/; domain=.google.com; HttpOnly^M P3P: CP="This is not a P3P policy! See http://www.google.com/support/accounts/bin/answer.py?hl=en&amp;answer=151657 for more info."^M Content-Encoding: gzip^M Transfer-Encoding: chunked^M Server: gws^M X-XSS-Protection: 1; mode=block^M X-Frame-Options: SAMEORIGIN^M ^M 907a^M </code></pre> <p>The number 907a in hex format is the chunk size missed in my HTTP response file. </p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload