curl onWrite() How to know when all data is in?

34 views
Skip to first unread message

PaulANormanNZ

unread,
Oct 11, 2011, 7:06:23 AM10/11/11
to glues...@googlegroups.com
HI,

I've been working with another local server using GLUEscript curl.

I am having problem knowing when all the data is in before writing out  NET response.print

Does curl.Info.SIZE_DOWNLOAD report the size sent by the Content-Length: header?

This is my trial code (response) is from a GLUEscript "net" HTTPserver which is working well.

                 var curl = require("curl");
 var c = new curl.Easy();

   var html = '';
        
  c.onWrite = function(data)
    {
    html += data.decodeToString();          
    }
 
var resp =  c.perform();  
while(html.length < c.getinfo(curl.Info.SIZE_DOWNLOAD))
{

}
  response.contentType="text/html";
  response.print( html );

I never get the complete output. Only about 1400 characters.

My error code for  c.perform();    is 23

The following code is what is writing the response. It works fine when driectly shown in a browser window from the same address that  
c.url = "http://localhost:8000/phpInfo.php"; is looking to.

<?php
  $phpinfoHtml =  phpinfo();  

   $fsize = mb_strlen($phpinfoHtml);
// tried this instead:  $fsize = strlen($phpinfoHtml);

    header("Content-Type: text/html"); 
    header("Content-Length: ".$fsize); 

 echo $phpinfoHtml;

?>

Are there more headers that curl is expecting?

Or is it my GLUEscript code please?

Paul



Franky Braem

unread,
Oct 12, 2011, 4:02:20 AM10/12/11
to GLUEscript
Paul,

You need to return a value from onWrite:

The return value should be the number of bytes actually used from the
buffer. When this amount differs from the size of the buffer, curl
will report an error and will abort the transfer.

Franky.

PS. I'll try to look at your other questions as soon as possible. I'm
currently very busy at work and unfortunately GLUEscript is sparetime
work ...

Paul A Norman

unread,
Oct 12, 2011, 4:47:14 AM10/12/11
to glues...@googlegroups.com
Thanks for that Frankie,

I changed my code as such ...

var x =   c.onWrite = function(data)
    {
    var chunk = data.decodeToString();
    html += chunk;
                return chunk.length     
    }


And REMed out 

/* while(html.length < c.getinfo(curl.Info.SIZE_DOWNLOAD))
 {

 }
*/

And all works well now.

Paul

--
You received this message because you are subscribed to the Google Groups "GLUEscript" group.
To post to this group, send email to glues...@googlegroups.com.
To unsubscribe from this group, send email to gluescript+...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/gluescript?hl=en.


Reply all
Reply to author
Forward
0 new messages