Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

manage request timeout without destroying socket (for reuse)

  • Loading branch information...
commit f8550a80324cc1f66b4792f18a7ea925735b98dd 1 parent ed913b0
@jairajs89 authored
Showing with 16 additions and 9 deletions.
  1. +1 −1  package.json
  2. +15 −8 zerver.js
View
2  package.json
@@ -2,7 +2,7 @@
"author": "Jairaj Sethi <j@jairaj.org> (http://jairaj.org/)",
"name": "zerver",
"description": "client-integrated webapp server",
- "version": "0.6.13",
+ "version": "0.6.14",
"repository": {
"type": "git",
"url": "git://github.com/jairajs89/zerver.git"
View
23 zerver.js
@@ -247,18 +247,25 @@ function handleRequest (request, response) {
pathname = handler.pathname,
isApiCall = pathname.substr(0, API_URL_LENGTH + 2) === '/'+API_URL+'/';
- setRequestTimeout(request, response);
+ setRequestTimeout(response);
tryResponseFromCache(handler, pathname, isApiCall, dynamicResponse);
}
-function setRequestTimeout (request, response) {
- request.socket.removeAllListeners('timeout');
- request.socket.setTimeout(REQUEST_TIMEOUT);
- request.socket.once('timeout', function () {
- console.log('zerver: request timeout, closing socket');
- request.socket.destroy();
- });
+function setRequestTimeout (response) {
+ var responseEnd = response.end,
+ timeout;
+
+ timeout = setTimeout(function () {
+ console.log('zerver: request timeout');
+ response.end('');
+ }, REQUEST_TIMEOUT);
+
+ response.end = function () {
+ clearTimeout(timeout);
+ response.end = responseEnd;
+ response.end.apply(this, arguments);
+ };
}
function tryResponseFromCache (handler, pathname, isApiCall, fallback) {
Please sign in to comment.
Something went wrong with that request. Please try again.