Skip to content

Commit 7aaab33

Browse files
committed
asdf
0 parents  commit 7aaab33

File tree

7 files changed

+185
-0
lines changed

7 files changed

+185
-0
lines changed

.gitignore

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
# Compiled source #
2+
###################
3+
*.com
4+
*.class
5+
*.dll
6+
*.exe
7+
*.o
8+
*.so
9+
10+
# Packages #
11+
############
12+
# it's better to unpack these files and commit the raw source
13+
# git has its own built in compression methods
14+
*.7z
15+
*.dmg
16+
*.gz
17+
*.iso
18+
*.jar
19+
*.rar
20+
*.tar
21+
*.zip
22+
23+
# Logs and databases #
24+
######################
25+
*.log
26+
*.sql
27+
*.sqlite
28+
29+
# OS generated files #
30+
######################
31+
.DS_Store*
32+
ehthumbs.db
33+
Icon?
34+
Thumbs.db
35+
36+
# Node.js #
37+
###########
38+
lib-cov
39+
*.seed
40+
*.log
41+
*.csv
42+
*.dat
43+
*.out
44+
*.pid
45+
*.gz
46+
47+
pids
48+
logs
49+
results
50+
51+
node_modules
52+
npm-debug.log
53+
54+
# Git #
55+
#######
56+
*.orig
57+
*.BASE.*
58+
*.BACKUP.*
59+
*.LOCAL.*
60+
*.REMOTE.*
61+
62+
# Components #
63+
##############
64+
65+
/build
66+
/components
67+
/landing/components
68+
.elasticbeanstalk/

.npmignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
test

Makefile

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
BIN = ./node_modules/.bin/
2+
3+
test:
4+
@$(BIN)mocha \
5+
--require should \
6+
--reporter spec \
7+
--bail
8+
9+
.PHONY: test

README.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Response Time
2+
3+
Response time middleware extracted from connect.
4+
5+
Usage:
6+
7+
```js
8+
var responseTime = require('response-time');
9+
10+
app.use(responseTime());
11+
```
12+
13+
## License
14+
15+
The MIT License (MIT)
16+
17+
Copyright (c) 2014 Jonathan Ong me@jongleberry.com
18+
19+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
20+
21+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
22+
23+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

index.js

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
2+
/*!
3+
* Connect - responseTime
4+
* Copyright(c) 2011 TJ Holowaychuk
5+
* MIT Licensed
6+
*/
7+
8+
/**
9+
* Reponse time:
10+
*
11+
* Adds the `X-Response-Time` header displaying the response
12+
* duration in milliseconds.
13+
*
14+
* @return {Function}
15+
* @api public
16+
*/
17+
18+
module.exports = function responseTime(){
19+
return function(req, res, next){
20+
next = next || noop;
21+
if (res._responseTime) return next();
22+
var writeHead = res.writeHead;
23+
var start = Date.now();
24+
res._responseTime = true;
25+
res.writeHead = function(){
26+
var duration = Date.now() - start;
27+
res.setHeader('X-Response-Time', duration + 'ms');
28+
writeHead.apply(res, arguments);
29+
};
30+
next();
31+
};
32+
};
33+
34+
function noop() {};

package.json

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
{
2+
"name": "response-time",
3+
"description": "X-Response-Time header for node.js",
4+
"version": "1.0.0",
5+
"author": {
6+
"name": "Jonathan Ong",
7+
"email": "me@jongleberry.com",
8+
"url": "http://jongleberry.com",
9+
"twitter": "https://twitter.com/jongleberry"
10+
},
11+
"license": "MIT",
12+
"repository": {
13+
"type": "git",
14+
"url": "https://github.com/expressjs/response-time.git"
15+
},
16+
"bugs": {
17+
"mail": "me@jongleberry.com",
18+
"url": "https://github.com/expressjs/response-time/issues"
19+
},
20+
"devDependencies": {
21+
"mocha": "*",
22+
"should": "*",
23+
"supertest": "*"
24+
},
25+
"scripts": {
26+
"test": "make test"
27+
}
28+
}

test/test.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
var http = require('http');
2+
var request = require('supertest');
3+
4+
var responseTime = require('..')();
5+
6+
describe('Response Time', function () {
7+
it('should set the response time header', function (done) {
8+
var server = http.createServer(function (req, res) {
9+
responseTime(req, res);
10+
setTimeout(function () {
11+
res.statusCode = 204;
12+
res.end();
13+
}, 10)
14+
})
15+
16+
request(server)
17+
.get('/')
18+
.expect(204)
19+
.expect('X-Response-Time', /1[0-9]ms/)
20+
.end(done);
21+
})
22+
})

0 commit comments

Comments
 (0)