diff --git a/core/httpd.js b/core/httpd.js index f3fa120a..a104aa1e 100644 --- a/core/httpd.js +++ b/core/httpd.js @@ -358,10 +358,12 @@ function badRequest(client, reason) { gBadRequests[client.peerName] = { expire: new Date(now.getTime() + 10 * 60 * 1000), count: 1, + reason: reason, }; count = 1; } else { old.count++; + old.reason = reason; count = old.count; } new Response({version: '1.0'}, client).reportError(reason + ': ' + count); @@ -385,7 +387,7 @@ function allowRequest(client) { function handleConnection(client) { if (!allowRequest(client)) { - print('Rejecting client for too many bad requests: ', client.peerName); + print('Rejecting client for too many bad requests: ', client.peerName, gBadRequests[client.peerName].reason); client.close(); return; } @@ -401,7 +403,11 @@ function handleConnection(client) { function resetTimeout(requestIndex) { setTimeout(function() { if (bodyToRead == -1 && requestCount == requestIndex) { - badRequest(client, 'Timed out waiting for request.'); + if (requestCount == 0) { + badRequest(client, 'Timed out waiting for request.'); + } else { + client.close(); + } } }, kRequestTimeout); } @@ -470,6 +476,8 @@ function handleConnection(client) { var requestObject = new Request(request[0], request[1], request[2], headers, body, client); var response = new Response(requestObject, client); handleWebSocketRequest(requestObject, response, client); + /* Prevent the timeout from disconnecting us. */ + requestCount++; return false; } else { finish();