diff --git a/core/httpd.js b/core/httpd.js index 27dd5966..f3fa120a 100644 --- a/core/httpd.js +++ b/core/httpd.js @@ -4,6 +4,8 @@ var gHandlers = []; var gSocketHandlers = []; var gBadRequests = {}; +const kRequestTimeout = 15000; + function logError(error) { print("ERROR " + error); if (error.stackTrace) { @@ -394,6 +396,17 @@ function handleConnection(client) { var lineByLine = true; var bodyToRead = -1; var body; + var requestCount = -1; + + function resetTimeout(requestIndex) { + setTimeout(function() { + if (bodyToRead == -1 && requestCount == requestIndex) { + badRequest(client, 'Timed out waiting for request.'); + } + }, kRequestTimeout); + } + + resetTimeout(++requestCount); function reset() { inputBuffer = new Uint8Array(0); @@ -402,6 +415,7 @@ function handleConnection(client) { lineByLine = true; bodyToRead = -1; body = undefined; + resetTimeout(++requestCount); } function finish() {