diff --git a/modules/network/http/http.js b/modules/network/http/http.js index f2a68c1deb..337a52bd8e 100644 --- a/modules/network/http/http.js +++ b/modules/network/http/http.js @@ -490,6 +490,10 @@ function server(message, value, etc) { delete this.line; let request = this.callback(Server.headersComplete); // headers complete... let's see what to do with the request body + if ('upgrade' === request) { + return; + } + if (false === request) delete this.total; // ignore request body and just send response @@ -592,53 +596,54 @@ function server(message, value, etc) { let first; if (7 === this.state) { - let response = this.callback(Server.prepareResponse); // prepare response - - let parts = []; - let status = (!response || (undefined === response.status)) ? 200 : response.status; - let message = (!response || (undefined === response.reason)) ? reason(status) : response.reason.toString(); - parts.push("HTTP/1.1 ", status.toString(), " ", message, "\r\n", - "connection: ", "close\r\n"); - - if (response) { - let byteLength; - - for (let i = 0, headers = response.headers; headers && (i < headers.length); i += 2) { - parts.push(headers[i], ": ", headers[i + 1].toString(), "\r\n"); - if ("content-length" == headers[i].toLowerCase()) - byteLength = parseInt(headers[i + 1]); - } + let responseP = Promise.resolve(this.callback(Server.prepareResponse)); // prepare response + responseP.then(response => { + let parts = []; + let status = (!response || (undefined === response.status)) ? 200 : response.status; + let message = (!response || (undefined === response.reason)) ? reason(status) : response.reason.toString(); + parts.push("HTTP/1.1 ", status.toString(), " ", message, "\r\n", + "connection: ", "close\r\n"); + + if (response) { + let byteLength; + + for (let i = 0, headers = response.headers; headers && (i < headers.length); i += 2) { + parts.push(headers[i], ": ", headers[i + 1].toString(), "\r\n"); + if ("content-length" == headers[i].toLowerCase()) + byteLength = parseInt(headers[i + 1]); + } - this.body = response.body; - if (true === response.body) { - if (undefined === byteLength) { - this.flags = 2; - parts.push("transfer-encoding: chunked\r\n"); + this.body = response.body; + if (true === response.body) { + if (undefined === byteLength) { + this.flags = 2; + parts.push("transfer-encoding: chunked\r\n"); + } + else + this.flags = 4; + } + else { + this.flags = 1; + let count = 0; + if (this.body) + count = ("string" === typeof this.body) ? this.body.length : this.body.byteLength; //@@ utf-8 hell + parts.push("content-length: ", count.toString(), "\r\n"); } - else - this.flags = 4; - } - else { - this.flags = 1; - let count = 0; - if (this.body) - count = ("string" === typeof this.body) ? this.body.length : this.body.byteLength; //@@ utf-8 hell - parts.push("content-length: ", count.toString(), "\r\n"); } - } - else - parts.push("content-length: 0\r\n"); - parts.push("\r\n"); - socket.write.apply(socket, parts); + else + parts.push("content-length: 0\r\n"); + parts.push("\r\n"); + socket.write.apply(socket, parts); - this.state = 8; - first = true; + this.state = 8; + first = true; - if (this.body && (true !== this.body)) { - let count = ("string" === typeof this.body) ? this.body.length : this.body.byteLength; - if (count > (socket.write() - ((2 & this.flags) ? 8 : 0))) - return; - } + if (this.body && (true !== this.body)) { + let count = ("string" === typeof this.body) ? this.body.length : this.body.byteLength; + if (count > (socket.write() - ((2 & this.flags) ? 8 : 0))) + return; + } + }); } if (8 === this.state) { let body = this.body; diff --git a/modules/network/socket/lin/modSocket.c b/modules/network/socket/lin/modSocket.c index c199e4725b..08550fcd4c 100644 --- a/modules/network/socket/lin/modSocket.c +++ b/modules/network/socket/lin/modSocket.c @@ -43,7 +43,7 @@ #define kRAW (2) #define kRxBufferSize 1024 -#define kTxBufferSize 1024 +#define kTxBufferSize 4096 typedef struct xsSocketRecord xsSocketRecord; typedef xsSocketRecord *xsSocket;