-
This is the request message
GET /hello.txt HTTP/1.1
User-Agent: Espruino 2v04.401
Connection: close
Host: http://www.pur3.co.ukAnd this is the response message
RECV FROM:93.93.135.13:80
+IPD259
HTTP/1.1 200 OK
Date: Wed, 25 Mar 2020 02:30:54 GMT
Server: Apache/2.4.18 (Ubuntu)
Last-Modified: Fri, 15 Nov 2013 15:42:26 GMT
ETag: "d-4eb390b887c80"
Accept-Ranges: bytes
Content-Length: 13
Connection: close
Content-Type: text/plain
Hello World!
+IPCLOSE: 0,1I tried to put debuggers in two places. In this place, I can't reach the debugger 2.
debugger; // 1 http.get("http://www.pur3.co.uk/hello.txt", function(res) { debugger; //2 let str = ''; res.on('data', chunk => { console.log("chunk",chunk); str += chunk; }); res.on('end', () => { console.log("Get some test request contents: ---> ", str); }); });
And the second place here:
recv: function (sckt, maxLen) { if (sockData[sckt]) { console.log("ddddddddddddddd",sockData[sckt]) var r; console.log("recv", sockData[sckt].length); if (sockData[sckt].length > maxLen) { r = sockData[sckt].substr(0, maxLen); sockData[sckt] = sockData[sckt].substr(maxLen); console.log("recv", sockData[sckt]); } else { r = sockData[sckt]; sockData[sckt] = ""; console.log("recv | socks[sckt]", socks[sckt]); if (socks[sckt] == "DataClose") { dbg("Got DataClose - forcing close"); socks[sckt] = "closing"; } } console.log("[recv data]", r); debugger; // 3 return r; } if (socks[sckt] == "closing" || !socks[sckt]) return -1; // close it return ""; },
I can reach debugger 3. And then where the code goes puzzle me so much! What's the relation between Http.get() and recv()?
debug>step
return r; ^
debug>step
Value returned is ="Hello World!"
This might have the solution and a reasonable explanation:
My suggestion is to post the response data in it's entirety so that others may take a look and compare to what should be in the response packet.
Don't know but, could it be the use of the arrow functions not allowing binding to the http response object?