• Dear community,

    sorry for writing again about problems I experienced with Espruino. I used the latest build of 1.75.

    I experienced that the "close" event of the http response is not raised for the same get request. No matter how often I try. On the other side I am using the Express JS framework. With other HTTP clients it works well.

    
        var request = function() {
            var body = "";
            var options = {
                method: 'GET',
                host: '192.168.0.11',
                port: 3000,
                path: "http://localhost:3000/api/Entities/54fabe55ef581d7d5f8bcac1/tasks?filter[where][active]=true&filter[fields][id]=true&access_token=I9sbI5cy6m1gHONeNmCHULGX4CwSGBzC0RDdnPDCfMW4or2UmDyxWg0ZbnQAT1yN",
                headers: {
                    "Content-Type": "application/json",
                    "Content-Length": body.length
                }
            };
            var contents = "";
            var req = require('http').request(options, function(res) {
                console.log(res);
                res.on('data', function(data) {
                    contents += data;
                });
                res.on('close', function() {
                    console.log('CLOSE');
                    if(res.statusCode === "200" || res.statusCode === "204") {
                        console.log('OK');
                    } else {
                        console.log('FAIL');
                    }
                    contents = "";
                });
    
            });
            req.on('error', function(e) {
                console.log('Error');
            });
            req.write(body);
            req.end();
        };
    

    The response looks ok:

    {
      "headers": {
        "X-Powered-By": "Express",
        "Vary": "Origin, Accept-Encoding",
        "Access-Control-Allow-Credentials": "true",
        "Content-Type": "application/json; charset=utf-8",
        "Content-Length": "2",
        "ETag": "W/\"2-d4cbb29\"",
        "Date": "Wed, 11 Mar 2015 13:30:53 GMT",
        "Connection": "close"
       },
      "httpVersion": "1.1",
      "statusCode": "200",
      "statusMessage": "OK",
      "#ondata": function (b) {l+=b}
     }
    

    How can I handle such problems with the http class of Espruino? What is the problem, that the "close"-event handler is not getting called?

    Best,

    Tobias

About

Avatar for net-tobi @net-tobi started