<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40">

<head>
<meta http-equiv=Content-Type content="text/html; charset=us-ascii">
<meta name=Generator content="Microsoft Word 12 (filtered medium)">
<style>
<!--
 /* Font Definitions */
 @font-face
        {font-family:Wingdings;
        panose-1:5 0 0 0 0 0 0 0 0 0;}
@font-face
        {font-family:PMingLiU;
        panose-1:2 2 3 0 0 0 0 0 0 0;}
@font-face
        {font-family:"Cambria Math";
        panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
        {font-family:Calibri;
        panose-1:2 15 5 2 2 2 4 3 2 4;}
@font-face
        {font-family:Tahoma;
        panose-1:2 11 6 4 3 5 4 4 2 4;}
@font-face
        {font-family:"\@PMingLiU";
        panose-1:2 2 3 0 0 0 0 0 0 0;}
 /* Style Definitions */
 p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0cm;
        margin-bottom:.0001pt;
        font-size:11.0pt;
        font-family:"Calibri","sans-serif";}
a:link, span.MsoHyperlink
        {mso-style-priority:99;
        color:blue;
        text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
        {mso-style-priority:99;
        color:purple;
        text-decoration:underline;}
p.MsoAcetate, li.MsoAcetate, div.MsoAcetate
        {mso-style-priority:99;
        mso-style-link:"Balloon Text Char";
        margin:0cm;
        margin-bottom:.0001pt;
        font-size:8.0pt;
        font-family:"Tahoma","sans-serif";}
p.MsoListParagraph, li.MsoListParagraph, div.MsoListParagraph
        {mso-style-priority:34;
        margin-top:0cm;
        margin-right:0cm;
        margin-bottom:0cm;
        margin-left:36.0pt;
        margin-bottom:.0001pt;
        font-size:11.0pt;
        font-family:"Calibri","sans-serif";}
span.EmailStyle17
        {mso-style-type:personal-compose;
        font-family:"Calibri","sans-serif";
        color:windowtext;}
span.BalloonTextChar
        {mso-style-name:"Balloon Text Char";
        mso-style-priority:99;
        mso-style-link:"Balloon Text";
        font-family:"Tahoma","sans-serif";}
.MsoChpDefault
        {mso-style-type:export-only;}
@page Section1
        {size:612.0pt 792.0pt;
        margin:72.0pt 72.0pt 72.0pt 72.0pt;}
div.Section1
        {page:Section1;}
 /* List Definitions */
 @list l0
        {mso-list-id:531111778;
        mso-list-type:hybrid;
        mso-list-template-ids:1027618200 -1319861076 67698691 67698693 67698689 67698691 67698693 67698689 67698691 67698693;}
@list l0:level1
        {mso-level-start-at:28;
        mso-level-number-format:bullet;
        mso-level-text:-;
        mso-level-tab-stop:none;
        mso-level-number-position:left;
        text-indent:-18.0pt;
        font-family:"Calibri","sans-serif";
        mso-fareast-font-family:PMingLiU;
        mso-bidi-font-family:"Times New Roman";}
ol
        {margin-bottom:0cm;}
ul
        {margin-bottom:0cm;}
-->
</style>
<!--[if gte mso 9]><xml>
 <o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
 <o:shapelayout v:ext="edit">
  <o:idmap v:ext="edit" data="1" />
 </o:shapelayout></xml><![endif]-->
</head>

<body lang=EN-US link=blue vlink=purple>

<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>&nbsp;</o:p></span></p>

<p class=MsoNormal><span style='font-family:"Courier New"'>I&#8217;ve been
making Javascript curl requests and have found that larger requests sometimes
come back incomplete. &nbsp;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"'>&nbsp;&nbsp;&nbsp; console_log(&quot;info&quot;,
&quot;returned body:&quot; + string + &quot;\n&quot;);<o:p></o:p></span></p>

<p class=MsoNormal><span style='font-family:"Courier New"'>&nbsp;&nbsp;&nbsp; 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>&nbsp;</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(&quot;GET&quot;, url, args, callback, arg, &quot;&quot;);<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>&nbsp;</o:p></span></p>

<p class=MsoNormal><span style='font-family:"Courier New"'>comparing &#8216;string&#8217;
with tcpdump, I found that &#8216;string&#8217; is definitely incomplete vs.
tcpdump.<o:p></o:p></span></p>

<p class=MsoNormal><span style='font-family:"Courier New"'><o:p>&nbsp;</o:p></span></p>

<p class=MsoNormal><span style='font-family:"Courier New"'>I&#8217;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>&nbsp;</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"'>{&#8230;}<o:p></o:p></span></p>

<p class=MsoNormal><span style='font-family:"Courier New"'><o:p>&nbsp;</o:p></span></p>

<p class=MsoNormal><span style='font-family:"Courier New"'>curl_easy_setopt(co-&gt;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-&gt;curl_handle,
CURLOPT_WRITEDATA, (void *) co);<o:p></o:p></span></p>

<p class=MsoNormal><span style='font-family:"Courier New"'><o:p>&nbsp;</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>&nbsp;</o:p></span></p>

<p class=MsoListParagraph style='text-indent:-18.0pt;mso-list:l0 level1 lfo1'><![if !supportLists]><span
style='mso-list:Ignore'>-<span style='font:7.0pt "Times New Roman"'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
</span></span><![endif]><span style='font-family:"Courier New"'>From <a
href="http://curl.netmirror.org/libcurl/c/curl_easy_setopt.html">http://curl.netmirror.org/libcurl/c/curl_easy_setopt.html</a>:
&#8220;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.&#8221;&nbsp;
>From this, I think that it is the callback&#8217;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>&nbsp;</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>&nbsp;</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"'>&nbsp;&nbsp;&nbsp;
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,&quot;BODY STUFF::::::%s\n&quot;, (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>&nbsp;</o:p></span></p>

<p class=MsoNormal><span style='font-family:"Courier New"'>I recompiled and
reproduced the offending http request.&nbsp; I found that the log is called
twice, with each log comprising both pieces of the complete response.&nbsp;
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>&nbsp;</o:p></span></p>

<p class=MsoNormal><span style='font-family:"Courier New"'>I&#8217;m not sure
if I&#8217;m using this correctly or if my analysis is correct, so if someone
can provide me some feedback, that&#8217;d be great.&nbsp; If it&#8217;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>&nbsp;</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>

</body>

</html>