<html><body bgcolor="#FFFFFF"><div>The analysis looks good, but how in the API do we know when the response is complete? Can you please open a bug on jira.freeswitch.org for this so we can track it.</div><div><br class="webkit-block-placeholder"></div><div>Thanks</div><div>Mike<br><br>On Jul 15, 2008, at 8:12 PM, "Simon Tang" <<a href="mailto:simon@airg.com">simon@airg.com</a>> wrote:<br><br></div><div></div><blockquote type="cite"><div>
<div class="Section1">
<p class="MsoNormal"><span style="font-family:"Courier New"">Hello,<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Courier New""><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Courier New"">I’ve been
making Javascript curl requests and have found that larger requests sometimes
come back incomplete. This is what I am doing in javascript:<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Courier New"">------------<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Courier New"">function
callback(string, arg)<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Courier New"">{<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Courier New""> console_log("info",
"returned body:" + string + "\n");<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Courier New""> return
true;<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Courier New"">}<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Courier New""><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Courier New"">var curl = new
CURL();<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Courier New"">var blah =
curl.run("GET", url, args, callback, arg, "");<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Courier New"">--------------<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Courier New""><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Courier New"">comparing ‘string’
with tcpdump, I found that ‘string’ is definitely incomplete vs.
tcpdump.<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Courier New""><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Courier New"">I’ve looked
into spidermokey_curl.c and found this code (excerpts):<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Courier New""><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Courier New"">static size_t
file_callback(void *ptr, size_t size, size_t nmemb, void *data)<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Courier New"">{…}<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Courier New""><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Courier New"">curl_easy_setopt(co->curl_handle,
CURLOPT_WRITEFUNCTION, file_callback);<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Courier New"">curl_easy_setopt(co->curl_handle,
CURLOPT_WRITEDATA, (void *) co);<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Courier New""><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Courier New"">I had the suspicion
that the callback is getting a partial response and passing it into the JS
object as a completed response:<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Courier New""><o:p> </o:p></span></p>
<p class="MsoListParagraph" style="text-indent:-18.0pt;mso-list:l0 level1 lfo1"><span style="mso-list:Ignore">-<span style="font:7.0pt "Times New Roman"">
</span></span><span style="font-family:"Courier New"">From <a href="http://curl.netmirror.org/libcurl/c/curl_easy_setopt.html"><a href="http://curl.netmirror.org/libcurl/c/curl_easy_setopt.html">http://curl.netmirror.org/libcurl/c/curl_easy_setopt.html</a></a>:
“The callback function will be passed as much data as possible in all
invokes, but you cannot possibly make any assumptions. It may be one byte, it
may be thousands. The maximum amount of data that can be passed to the write
callback is defined in the curl.h header file: CURL_MAX_WRITE_SIZE.”
>From this, I think that it is the callback’s responsibility to ensure
that the complete response was received and to save the data somewhere.<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Courier New""><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Courier New"">To confirm my
suspicion, I replaced the callback function in spidermonkey_curl.c with vanilla
logging and took out the JSAPI references:<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Courier New""><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Courier New"">static size_t
file_callback(void *ptr, size_t size, size_t nmemb, void *data)<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Courier New"">{<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Courier New"">
register unsigned int realsize = (unsigned int) (size * nmemb);<o:p></o:p></span></p>
<p class="MsoNormal" style="text-indent:27.0pt"><span style="font-family:"Courier New"">switch_log_printf(SWITCH_CHANNEL_LOG,
SWITCH_LOG_DEBUG,"BODY STUFF::::::%s\n", (char*) ptr);<o:p></o:p></span></p>
<p class="MsoNormal" style="text-indent:27.0pt"><span style="font-family:"Courier New"">return
realsize;<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Courier New"">}<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Courier New""><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Courier New"">I recompiled and
reproduced the offending http request. I found that the log is called
twice, with each log comprising both pieces of the complete response.
When I reverted back to the original file_callback function and added a log in
there, the log only recorded the first part of the response (incomplete).<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Courier New""><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Courier New"">I’m not sure
if I’m using this correctly or if my analysis is correct, so if someone
can provide me some feedback, that’d be great. If it’s a
legit bug, I can file it.<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Courier New""><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-CA" style="font-size:10.0pt;font-family:"Courier New"">Simon
Tang<o:p></o:p></span></p>
</div>
</div></blockquote><blockquote type="cite"><div><span>_______________________________________________</span><br><span>Freeswitch-users mailing list</span><br><span><a href="mailto:Freeswitch-users@lists.freeswitch.org">Freeswitch-users@lists.freeswitch.org</a></span><br><span><a href="http://lists.freeswitch.org/mailman/listinfo/freeswitch-users">http://lists.freeswitch.org/mailman/listinfo/freeswitch-users</a></span><br><span>UNSUBSCRIBE:<a href="http://lists.freeswitch.org/mailman/options/freeswitch-users"><a href="http://lists.freeswitch.org/mailman/options/freeswitch-users">http://lists.freeswitch.org/mailman/options/freeswitch-users</a></a></span><br><span><a href="http://www.freeswitch.org">http://www.freeswitch.org</a></span><br></div></blockquote></body></html>