@@ -28,23 +28,23 @@ var onHeaders = require('on-headers');
28
28
*/
29
29
30
30
module . exports = function timeout ( time , options ) {
31
- options = options || { } ;
31
+ var opts = options || { } ;
32
32
33
- time = typeof time === 'string'
33
+ var delay = typeof time === 'string'
34
34
? ms ( time )
35
35
: Number ( time || 5000 ) ;
36
36
37
- var respond = ! ( 'respond' in options ) || options . respond === true ;
37
+ var respond = ! ( 'respond' in opts ) || opts . respond === true ;
38
38
39
39
return function ( req , res , next ) {
40
40
var destroy = req . socket . destroy ;
41
41
var id = setTimeout ( function ( ) {
42
42
req . timedout = true ;
43
- req . emit ( 'timeout' , time ) ;
44
- } , time ) ;
43
+ req . emit ( 'timeout' , delay ) ;
44
+ } , delay ) ;
45
45
46
46
if ( respond ) {
47
- req . on ( 'timeout' , onTimeout ( time , next ) ) ;
47
+ req . on ( 'timeout' , onTimeout ( delay , next ) ) ;
48
48
}
49
49
50
50
req . clearTimeout = function ( ) {
@@ -66,11 +66,11 @@ module.exports = function timeout(time, options) {
66
66
} ;
67
67
} ;
68
68
69
- function onTimeout ( time , cb ) {
69
+ function onTimeout ( delay , cb ) {
70
70
return function ( ) {
71
71
cb ( createError ( 503 , 'Response timeout' , {
72
72
code : 'ETIMEDOUT' ,
73
- timeout : time
73
+ timeout : delay
74
74
} ) ) ;
75
75
} ;
76
76
}
0 commit comments