Espruino/tests/test_http_headers.js
Standa Opichal faf7157093 Fix receiving of large HTTP headers
Added a test which sends HTTP headers which take more than
MSS bytes (536) and therefore the httpParseHeaders() needs to be
called later again after the next packet arrives.

Fixes #1405
2018-05-12 22:15:03 +02:00

60 lines
1.3 KiB
JavaScript

// HTTP Headers longer than MSS server and client test
var result = 0;
var http = require("http");
var server = http.createServer(function (req, res) {
console.log("Connected");
var body = '';
req.on('data', function(data) {
console.log("<" + data);
body += data;
});
req.on('end', function() {
console.log("<end");
res.writeHead(200);
res.end('42'+body+req.headers['X-Check']);
});
req.on('close', function() {
console.log("<close");
});
req.on('error', function(e) {
console.log("<error: " + e.message);
});
});
server.listen(8080);
var options = {
host: 'localhost',
port: 8080,
path: '/post.html',
method: 'POST',
protocol: 'http:',
headers: {
'X-LongHeader': new Array(35).fill('long header item').join(','),
'X-Check': '24'
}
};
var req = http.request(options, function(res) {
console.log(">RES ", res.headers);
var body = '';
res.on('data', function(data) {
console.log(">" + data);
body += data;
});
res.on('end', function() {
console.log(">END");
server.close();
result = body=="42-0123456789abcdef-24";
});
res.on('close', function() {
console.log(">CLOSE");
});
})
req.on('error', function(e) {
console.log(">ERROR: " + e.message);
});
req.end('-0123456789abcdef-'); // longer than 15 chars