mirror of
https://github.com/seejohnrun/haste-server
synced 2025-07-14 17:13:45 -07:00
Added node modules
This commit is contained in:
parent
ca9d4c18f7
commit
d1e0644a4e
575 changed files with 77900 additions and 6 deletions
34
node_modules/connect/lib/middleware/responseTime.js
generated
vendored
Normal file
34
node_modules/connect/lib/middleware/responseTime.js
generated
vendored
Normal file
|
@ -0,0 +1,34 @@
|
|||
|
||||
/*!
|
||||
* Connect - responseTime
|
||||
* Copyright(c) 2011 TJ Holowaychuk
|
||||
* MIT Licensed
|
||||
*/
|
||||
|
||||
/**
|
||||
* Adds the `X-Response-Time` header displaying the response
|
||||
* duration in milliseconds.
|
||||
*
|
||||
* @return {Function}
|
||||
* @api public
|
||||
*/
|
||||
|
||||
module.exports = function responseTime(){
|
||||
return function(req, res, next){
|
||||
var writeHead = res.writeHead
|
||||
, start = new Date;
|
||||
|
||||
if (res._responseTime) return next();
|
||||
res._responseTime = true;
|
||||
|
||||
// proxy writeHead to calculate duration
|
||||
res.writeHead = function(status, headers){
|
||||
var duration = new Date - start;
|
||||
res.setHeader('X-Response-Time', duration + 'ms');
|
||||
res.writeHead = writeHead;
|
||||
res.writeHead(status, headers);
|
||||
};
|
||||
|
||||
next();
|
||||
};
|
||||
};
|
Loading…
Add table
Add a link
Reference in a new issue