mirror of
https://github.com/arnaucube/raspberryGPIOhtmlserver.git
synced 2026-02-08 04:06:43 +01:00
servidor funciona, gpio desabilitat
This commit is contained in:
55
node_modules/connect/lib/middleware/timeout.js
generated
vendored
Executable file
55
node_modules/connect/lib/middleware/timeout.js
generated
vendored
Executable file
@@ -0,0 +1,55 @@
|
||||
/*!
|
||||
* Connect - timeout
|
||||
* Ported from https://github.com/LearnBoost/connect-timeout
|
||||
* MIT Licensed
|
||||
*/
|
||||
|
||||
/**
|
||||
* Module dependencies.
|
||||
*/
|
||||
|
||||
var debug = require('debug')('connect:timeout');
|
||||
|
||||
/**
|
||||
* Timeout:
|
||||
*
|
||||
* Times out the request in `ms`, defaulting to `5000`. The
|
||||
* method `req.clearTimeout()` is added to revert this behaviour
|
||||
* programmatically within your application's middleware, routes, etc.
|
||||
*
|
||||
* The timeout error is passed to `next()` so that you may customize
|
||||
* the response behaviour. This error has the `.timeout` property as
|
||||
* well as `.status == 408`.
|
||||
*
|
||||
* @param {Number} ms
|
||||
* @return {Function}
|
||||
* @api public
|
||||
*/
|
||||
|
||||
module.exports = function timeout(ms) {
|
||||
ms = ms || 5000;
|
||||
|
||||
return function(req, res, next) {
|
||||
var id = setTimeout(function(){
|
||||
req.emit('timeout', ms);
|
||||
}, ms);
|
||||
|
||||
req.on('timeout', function(){
|
||||
if (res.headerSent) return debug('response started, cannot timeout');
|
||||
var err = new Error('Response timeout');
|
||||
err.timeout = ms;
|
||||
err.status = 503;
|
||||
next(err);
|
||||
});
|
||||
|
||||
req.clearTimeout = function(){
|
||||
clearTimeout(id);
|
||||
};
|
||||
|
||||
res.on('header', function(){
|
||||
clearTimeout(id);
|
||||
});
|
||||
|
||||
next();
|
||||
};
|
||||
};
|
||||
Reference in New Issue
Block a user