Compare commits

...

81 Commits
4.3.2 ... 4.4.4

Author SHA1 Message Date
Douglas Christopher Wilson
f498b660da 4.4.4 2014-06-20 16:56:51 -04:00
刘星
e606d99dc8 Fix res.attachment Unicode filenames in Safari
closes #2188
2014-06-20 16:55:05 -04:00
Douglas Christopher Wilson
6aba1b4c49 deps: accepts@~1.0.5 2014-06-20 16:44:50 -04:00
Douglas Christopher Wilson
6ee9433f29 deps: update example dependencies 2014-06-20 16:43:04 -04:00
Douglas Christopher Wilson
ffe663aedf deps: buffer-crc32@0.2.3 2014-06-20 00:35:38 -04:00
Douglas Christopher Wilson
8258ce14f4 fix "trim prefix" debug message in express:router
closes #2177
2014-06-14 12:57:32 -04:00
Douglas Christopher Wilson
ac573cf830 4.4.3 2014-06-12 00:41:24 -04:00
Douglas Christopher Wilson
e799c0fb7b Merge tag '3.10.5' 2014-06-12 00:38:29 -04:00
Douglas Christopher Wilson
73c5533e66 3.10.5 2014-06-12 00:28:08 -04:00
Douglas Christopher Wilson
3b1f747f96 deps: send@0.4.3 2014-06-12 00:24:21 -04:00
Douglas Christopher Wilson
9e9827d236 deps: debug@1.0.2 2014-06-12 00:23:15 -04:00
Douglas Christopher Wilson
a76d508424 deps: connect@2.19.6 2014-06-12 00:20:30 -04:00
Douglas Christopher Wilson
c361a06bd4 deps: serve-static@1.2.3 2014-06-12 00:17:28 -04:00
Douglas Christopher Wilson
3428543bb8 deps: accepts@1.0.3 2014-06-12 00:16:05 -04:00
Douglas Christopher Wilson
9cdbc80522 deps: send@0.4.3 2014-06-12 00:14:36 -04:00
Douglas Christopher Wilson
6775658ed5 Fix persistence of req.params from app.params
fixes #2170
2014-06-11 18:15:09 -04:00
Douglas Christopher Wilson
7df7f7a575 deps: debug@1.0.2 2014-06-11 17:53:56 -04:00
Douglas Christopher Wilson
7daae1912b 4.4.2 2014-06-09 20:40:39 -04:00
Douglas Christopher Wilson
3205f68510 deps: update example dependencies 2014-06-09 20:39:34 -04:00
Douglas Christopher Wilson
898dcfac8b Merge tag '3.10.4' 2014-06-09 20:39:22 -04:00
Douglas Christopher Wilson
b1efa19f97 deps: update testing dependencies 2014-06-09 20:24:36 -04:00
Douglas Christopher Wilson
b45fd70f99 deps: send@0.4.2 2014-06-09 20:22:42 -04:00
Douglas Christopher Wilson
7f6c7a19c6 deps: serve-static@1.2.2 2014-06-09 20:21:31 -04:00
Douglas Christopher Wilson
142462d539 deps: debug@1.0.1 2014-06-09 20:20:50 -04:00
Douglas Christopher Wilson
f881784e9b 3.10.4 2014-06-09 18:53:52 -04:00
Douglas Christopher Wilson
5af625903f deps: send@0.4.2 2014-06-09 18:51:55 -04:00
Douglas Christopher Wilson
dc94f305cc deps: debug@1.0.1 2014-06-09 18:50:36 -04:00
Douglas Christopher Wilson
8060a49c6c deps: connect@2.19.5 2014-06-09 18:50:00 -04:00
Douglas Christopher Wilson
4d3e0d88a2 Fix catching errors from top-level handlers 2014-06-09 09:44:37 -04:00
Nick Heiner
253ce4837a Use path.resolve for views dir instead of concat
closes #2165
2014-06-08 17:41:36 -04:00
Joshua Goldberg
ad05eb8222 Fix typo in console.log in multipart example
closes #2164
2014-06-07 20:14:33 -04:00
Douglas Christopher Wilson
21393c244c tests: add more route tests 2014-06-06 11:12:52 -04:00
Douglas Christopher Wilson
4279e6ef45 improve before hook in mvc example 2014-06-06 10:42:29 -04:00
Douglas Christopher Wilson
3db6dd752f change confusing 404 handling in download example 2014-06-06 10:23:47 -04:00
Douglas Christopher Wilson
fcbe68eeb5 docs: move badges 2014-06-06 00:41:08 -04:00
Douglas Christopher Wilson
5019f38e29 tests: add more tests 2014-06-06 00:38:14 -04:00
Douglas Christopher Wilson
9bf1247716 Merge tag '3.10.3' 2014-06-05 23:45:31 -04:00
Douglas Christopher Wilson
2fd31f6ea6 3.10.3 2014-06-05 23:38:58 -04:00
Douglas Christopher Wilson
9cf7bba8f0 deps: connect@2.19.4 2014-06-05 23:37:22 -04:00
Douglas Christopher Wilson
2e257d1cf7 build: use compressed formats in package 2014-06-05 19:45:00 -04:00
Douglas Christopher Wilson
980a15d847 deps: type-is@1.2.1 2014-06-05 19:40:27 -04:00
Douglas Christopher Wilson
56831d7799 deps: debug@1.0.0 2014-06-05 19:34:05 -04:00
Jonathan Ong
6d65ae5ba6 use vary@0.1.0
with backwards compatibility

closes #2161
2014-06-05 19:32:32 -04:00
Douglas Christopher Wilson
c919b4a573 3.10.2 2014-06-03 21:35:34 -04:00
Douglas Christopher Wilson
fe6f392c2d deps: connect@2.19.3 2014-06-03 21:33:55 -04:00
Douglas Christopher Wilson
bffb71d4c8 deps: proxy-addr@1.0.1 2014-06-03 17:25:20 -04:00
Douglas Christopher Wilson
3b34a537ee 3.10.1 2014-06-03 16:45:09 -04:00
Douglas Christopher Wilson
ad79ce9c4b deps: connect@2.19.2 2014-06-03 16:44:29 -04:00
Douglas Christopher Wilson
721f6388c3 deps: proxy-addr@1.0.1 2014-06-03 16:42:49 -04:00
Douglas Christopher Wilson
402ec83157 Merge tag '3.10.0' 2014-06-03 00:47:39 -04:00
Douglas Christopher Wilson
298ac11018 3.10.0 2014-06-03 00:40:27 -04:00
Douglas Christopher Wilson
bb6e207336 deps: connect@2.19.1 2014-06-03 00:37:57 -04:00
Douglas Christopher Wilson
f433b7c7cf replace utils.escape with html-escape 2014-06-03 00:37:32 -04:00
Douglas Christopher Wilson
a94278abd1 deps: send@0.4.1 2014-06-02 21:31:23 -04:00
Douglas Christopher Wilson
f9ec70edd0 4.4.1 2014-06-02 21:13:50 -04:00
Douglas Christopher Wilson
9e5a758e7c deps: update example dependencies 2014-06-02 20:59:45 -04:00
Douglas Christopher Wilson
492e933796 deps: serve-static@1.2.1 2014-06-02 20:50:54 -04:00
Douglas Christopher Wilson
8ccd9d0eb5 deps: send@0.4.1 2014-06-02 20:49:11 -04:00
Douglas Christopher Wilson
16fdc11ccb deps: methods@1.0.1 2014-06-02 20:48:18 -04:00
Douglas Christopher Wilson
a7cd5a2553 deps: methods@1.0.1 2014-06-02 19:19:56 -04:00
Douglas Christopher Wilson
9e6b881f85 remove jsdoc params for polymorphic functions
until jsdoc has a way to actually document them

closes #2156
2014-06-02 10:26:15 -04:00
Douglas Christopher Wilson
95fa49147b 4.4.0 2014-05-31 00:00:39 -04:00
Douglas Christopher Wilson
f665c57c5c update serve-static to 1.2.0 2014-05-30 22:53:02 -04:00
Douglas Christopher Wilson
9024d24e81 deps: supertest@~0.13.0 2014-05-30 22:50:22 -04:00
Douglas Christopher Wilson
f92a7ad0a3 update accepts to 1.0.2 2014-05-30 22:48:32 -04:00
Douglas Christopher Wilson
db4448dda8 Merge tag '3.9.0' 2014-05-30 22:17:51 -04:00
Douglas Christopher Wilson
0dc5836d5e 3.9.0 2014-05-30 21:35:12 -04:00
Douglas Christopher Wilson
8751d7ecf8 tests: add more tests 2014-05-30 21:28:48 -04:00
Douglas Christopher Wilson
c21226aa7c improve etag control for res.send
closes #1435
closes #2129
2014-05-30 21:02:21 -04:00
Douglas Christopher Wilson
3e358458f4 tests: add more etag tests 2014-05-30 19:51:32 -04:00
Douglas Christopher Wilson
766b3aecf7 deps: update example dependencies 2014-05-29 23:39:52 -04:00
Douglas Christopher Wilson
8ab96ab80d mark res.send ETag as weak and reduce collisions 2014-05-29 23:14:21 -04:00
Douglas Christopher Wilson
1f2e00ef8d deps: should@~4.0.0 2014-05-29 22:53:59 -04:00
Douglas Christopher Wilson
b49453cf0d update send to 0.4.0
closes #2150
2014-05-29 22:32:03 -04:00
Douglas Christopher Wilson
faffcb889c update connect to 2.18.0 2014-05-29 22:21:53 -04:00
Tiago Relvao
3c0ec59432 Include ETag in HEAD requests
backport of commit 3c7310ebcb
2014-05-28 22:31:00 -04:00
Douglas Christopher Wilson
d4a2843500 tests: add param test with encoded value
closes #2143
2014-05-28 22:30:24 -04:00
Douglas Christopher Wilson
e7ad49bbbe tests: add accepts test with params 2014-05-28 00:30:29 -04:00
Douglas Christopher Wilson
ad9a414fae tests: add more acceptance tests 2014-05-28 00:24:24 -04:00
Douglas Christopher Wilson
c18c2a8e68 tests: exclude untestable lines in examples from coverage 2014-05-28 00:07:27 -04:00
Douglas Christopher Wilson
1d54868c12 update supertest to 0.13.0 2014-05-27 23:54:34 -04:00
73 changed files with 1034 additions and 395 deletions

View File

@@ -1,3 +1,75 @@
4.4.4 / 2014-06-20
==================
* fix `res.attachment` Unicode filenames in Safari
* fix "trim prefix" debug message in `express:router`
* deps: accepts@~1.0.5
* deps: buffer-crc32@0.2.3
4.4.3 / 2014-06-11
==================
* fix persistence of modified `req.params[name]` from `app.param()`
* deps: accepts@1.0.3
- deps: negotiator@0.4.6
* deps: debug@1.0.2
* deps: send@0.4.3
- Do not throw un-catchable error on file open race condition
- Use `escape-html` for HTML escaping
- deps: debug@1.0.2
- deps: finished@1.2.2
- deps: fresh@0.2.2
* deps: serve-static@1.2.3
- Do not throw un-catchable error on file open race condition
- deps: send@0.4.3
4.4.2 / 2014-06-09
==================
* fix catching errors from top-level handlers
* use `vary` module for `res.vary`
* deps: debug@1.0.1
* deps: proxy-addr@1.0.1
* deps: send@0.4.2
- fix "event emitter leak" warnings
- deps: debug@1.0.1
- deps: finished@1.2.1
* deps: serve-static@1.2.2
- fix "event emitter leak" warnings
- deps: send@0.4.2
* deps: type-is@1.2.1
4.4.1 / 2014-06-02
==================
* deps: methods@1.0.1
* deps: send@0.4.1
- Send `max-age` in `Cache-Control` in correct format
* deps: serve-static@1.2.1
- use `escape-html` for escaping
- deps: send@0.4.1
4.4.0 / 2014-05-30
==================
* custom etag control with `app.set('etag', val)`
- `app.set('etag', function(body, encoding){ return '"etag"' })` custom etag generation
- `app.set('etag', 'weak')` weak tag
- `app.set('etag', 'strong')` strong etag
- `app.set('etag', false)` turn off
- `app.set('etag', true)` standard etag
* mark `res.send` ETag as weak and reduce collisions
* update accepts to 1.0.2
- Fix interpretation when header not in request
* update send to 0.4.0
- Calculate ETag with md5 for reduced collisions
- Ignore stream errors after request ends
- deps: debug@0.8.1
* update serve-static to 1.2.0
- Calculate ETag with md5 for reduced collisions
- Ignore stream errors after request ends
- deps: send@0.4.0
4.3.2 / 2014-05-28
==================
@@ -124,6 +196,95 @@
- `app.route()` - Proxy to the app's `Router#route()` method to create a new route
- Router & Route - public API
3.10.5 / 2014-06-11
===================
* deps: connect@2.19.6
- deps: body-parser@1.3.1
- deps: compression@1.0.7
- deps: debug@1.0.2
- deps: serve-index@1.1.1
- deps: serve-static@1.2.3
* deps: debug@1.0.2
* deps: send@0.4.3
- Do not throw un-catchable error on file open race condition
- Use `escape-html` for HTML escaping
- deps: debug@1.0.2
- deps: finished@1.2.2
- deps: fresh@0.2.2
3.10.4 / 2014-06-09
===================
* deps: connect@2.19.5
- fix "event emitter leak" warnings
- deps: csurf@1.2.1
- deps: debug@1.0.1
- deps: serve-static@1.2.2
- deps: type-is@1.2.1
* deps: debug@1.0.1
* deps: send@0.4.2
- fix "event emitter leak" warnings
- deps: finished@1.2.1
- deps: debug@1.0.1
3.10.3 / 2014-06-05
===================
* use `vary` module for `res.vary`
* deps: connect@2.19.4
- deps: errorhandler@1.0.2
- deps: method-override@2.0.2
- deps: serve-favicon@2.0.1
* deps: debug@1.0.0
3.10.2 / 2014-06-03
===================
* deps: connect@2.19.3
- deps: compression@1.0.6
3.10.1 / 2014-06-03
===================
* deps: connect@2.19.2
- deps: compression@1.0.4
* deps: proxy-addr@1.0.1
3.10.0 / 2014-06-02
===================
* deps: connect@2.19.1
- deprecate `methodOverride()` -- use `method-override` module directly
- deps: body-parser@1.3.0
- deps: method-override@2.0.1
- deps: multiparty@3.2.8
- deps: response-time@2.0.0
- deps: serve-static@1.2.1
* deps: methods@1.0.1
* deps: send@0.4.1
- Send `max-age` in `Cache-Control` in correct format
3.9.0 / 2014-05-30
==================
* custom etag control with `app.set('etag', val)`
- `app.set('etag', function(body, encoding){ return '"etag"' })` custom etag generation
- `app.set('etag', 'weak')` weak tag
- `app.set('etag', 'strong')` strong etag
- `app.set('etag', false)` turn off
- `app.set('etag', true)` standard etag
* Include ETag in HEAD requests
* mark `res.send` ETag as weak and reduce collisions
* update connect to 2.18.0
- deps: compression@1.0.3
- deps: serve-index@1.1.0
- deps: serve-static@1.2.0
* update send to 0.4.0
- Calculate ETag with md5 for reduced collisions
- Ignore stream errors after request ends
- deps: debug@0.8.1
3.8.1 / 2014-05-27
==================

View File

@@ -2,7 +2,10 @@
Fast, unopinionated, minimalist web framework for [node](http://nodejs.org).
[![NPM version](https://badge.fury.io/js/express.svg)](http://badge.fury.io/js/express) [![Build Status](https://travis-ci.org/visionmedia/express.svg?branch=master)](https://travis-ci.org/visionmedia/express) [![Coverage Status](https://img.shields.io/coveralls/visionmedia/express.svg)](https://coveralls.io/r/visionmedia/express) [![Gittip](http://img.shields.io/gittip/visionmedia.svg)](https://www.gittip.com/visionmedia/)
[![NPM version](https://badge.fury.io/js/express.svg)](http://badge.fury.io/js/express)
[![Build Status](https://travis-ci.org/visionmedia/express.svg?branch=master)](https://travis-ci.org/visionmedia/express)
[![Coverage Status](https://img.shields.io/coveralls/visionmedia/express.svg)](https://coveralls.io/r/visionmedia/express)
[![Gittip](http://img.shields.io/gittip/visionmedia.svg)](https://www.gittip.com/visionmedia/)
```js
var express = require('express');

View File

@@ -5,7 +5,6 @@
var express = require('../..');
var hash = require('./pass').hash;
var bodyParser = require('body-parser');
var cookieParser = require('cookie-parser');
var session = require('express-session');
var app = module.exports = express();
@@ -17,9 +16,8 @@ app.set('views', __dirname + '/views');
// middleware
app.use(bodyParser());
app.use(cookieParser('shhhh, very secret'));
app.use(session());
app.use(bodyParser.urlencoded({ extended: false }));
app.use(session({ secret: 'shhhh, very secret' }));
// Session-persisted message middleware
@@ -121,6 +119,7 @@ app.post('/login', function(req, res){
});
});
/* istanbul ignore next */
if (!module.parent) {
app.listen(3000);
console.log('Express started on port 3000');

View File

@@ -24,5 +24,8 @@ app.get('/', function(req, res){
res.render('pets', { pets: pets });
});
app.listen(3000);
console.log('Express listening on port 3000');
/* istanbul ignore next */
if (!module.parent) {
app.listen(3000);
console.log('Express started on port 3000');
}

View File

@@ -37,7 +37,8 @@ function format(path) {
app.get('/users', format('./users'));
/* istanbul ignore next */
if (!module.parent) {
app.listen(3000);
console.log('listening on port 3000');
console.log('Express started on port 3000');
}

View File

@@ -3,15 +3,11 @@
*/
var express = require('../../');
var cookie-parser = require('cookie-parser');
var app = module.exports = express();
// pass a secret to cookieParser() for signed cookies
app.use(cookieParser('manny is cool'));
// add req.session cookie support
app.use(cookieSession());
app.use(cookieSession({ secret: 'manny is cool' }));
// do something with the session
app.use(count);
@@ -23,7 +19,8 @@ function count(req, res) {
res.send('viewed ' + n + ' times\n');
}
/* istanbul ignore next */
if (!module.parent) {
app.listen(3000);
console.log('Express server listening on port 3000');
console.log('Express started on port 3000');
}

View File

@@ -9,8 +9,7 @@ var cookieParser = require('cookie-parser');
var bodyParser = require('body-parser');
// custom log format
if ('test' != process.env.NODE_ENV)
app.use(logger(':method :url'));
if ('test' != process.env.NODE_ENV) app.use(logger(':method :url'));
// parses request cookies, populating
// req.cookies and req.signedCookies
@@ -18,8 +17,8 @@ if ('test' != process.env.NODE_ENV)
// for signing the cookies.
app.use(cookieParser('my secret here'));
// parses json, x-www-form-urlencoded, and multipart/form-data
app.use(bodyParser());
// parses x-www-form-urlencoded
app.use(bodyParser.urlencoded({ extended: false }));
app.get('/', function(req, res){
if (req.cookies.remember) {
@@ -42,7 +41,8 @@ app.post('/', function(req, res){
res.redirect('back');
});
if (!module.parent){
/* istanbul ignore next */
if (!module.parent) {
app.listen(3000);
console.log('Express started on port 3000');
}

View File

@@ -15,7 +15,7 @@ app.use(express.static(__dirname + '/public'));
// api middleware
api.use(logger('dev'));
api.use(bodyParser());
api.use(bodyParser.json());
/**
* CORS support.

View File

@@ -10,6 +10,7 @@ app.get('/', function(req, res){
+ '<li>Download <a href="/files/amazing.txt">amazing.txt</a>.</li>'
+ '<li>Download <a href="/files/utf-8 한中日.txt">utf-8 한中日.txt</a>.</li>'
+ '<li>Download <a href="/files/missing.txt">missing.txt</a>.</li>'
+ '<li>Download <a href="/files/CCTV大赛上海分赛区.txt">CCTV大赛上海分赛区.txt</a>.</li>'
+ '</ul>');
});
@@ -19,25 +20,16 @@ app.get('/files/:file(*)', function(req, res, next){
var file = req.params.file;
var path = __dirname + '/files/' + file;
res.download(path);
});
// error handling middleware. Because it's
// below our routes, you will be able to
// "intercept" errors, otherwise Connect
// will respond with 500 "Internal Server Error".
app.use(function(err, req, res, next){
// special-case 404s,
// remember you could
// render a 404 template here
if (404 == err.status) {
res.download(path, function(err){
if (!err) return; // file sent
if (err && err.status !== 404) return next(err); // non-404 error
// file for download not found
res.statusCode = 404;
res.send('Cant find that file, sorry!');
} else {
next(err);
}
});
});
/* istanbul ignore next */
if (!module.parent) {
app.listen(3000);
console.log('Express started on port 3000');

View File

@@ -0,0 +1,2 @@
Only for test.
The file name is faked.

View File

@@ -43,7 +43,8 @@ app.get('/', function(req, res){
});
});
/* istanbul ignore next */
if (!module.parent) {
app.listen(3000);
console.log('Express app started on port 3000');
console.log('Express started on port 3000');
}

View File

@@ -18,9 +18,7 @@ app.enable('verbose errors');
// disable them in production
// use $ NODE_ENV=production node examples/error-pages
if ('production' == app.settings.env) {
app.disable('verbose errors');
}
if ('production' == app.settings.env) app.disable('verbose errors');
silent || app.use(logger('dev'));
@@ -99,7 +97,8 @@ app.use(function(err, req, res, next){
});
/* istanbul ignore next */
if (!module.parent) {
app.listen(3000);
silent || console.log('Express started on port 3000');
console.log('Express started on port 3000');
}

View File

@@ -40,6 +40,7 @@ app.get('/next', function(req, res, next){
// from app.get() etc
app.use(error);
/* istanbul ignore next */
if (!module.parent) {
app.listen(3000);
console.log('Express started on port 3000');

View File

@@ -57,5 +57,8 @@ app.get('/user', function(req, res){
res.render('page');
});
app.listen(3000);
console.log('app listening on port 3000');
/* istanbul ignore next */
if (!module.parent) {
app.listen(3000);
console.log('Express started on port 3000');
}

View File

@@ -6,5 +6,8 @@ app.get('/', function(req, res){
res.send('Hello World');
});
app.listen(3000);
console.log('Express started on port 3000');
/* istanbul ignore next */
if (!module.parent) {
app.listen(3000);
console.log('Express started on port 3000');
}

View File

@@ -44,5 +44,8 @@ app.use(function(err, req, res, next) {
res.send(err.stack);
});
app.listen(3000);
console.log('Express app started on port 3000');
/* istanbul ignore next */
if (!module.parent) {
app.listen(3000);
console.log('Express started on port 3000');
}

View File

@@ -38,6 +38,7 @@ app.get('/fail', function(req, res){
res.render('missing', { title: 'Markdown Example' });
});
/* istanbul ignore next */
if (!module.parent) {
app.listen(3000);
console.log('Express started on port 3000');

View File

@@ -53,7 +53,8 @@ app.post('/', function(req, res, next){
form.parse(req);
});
/* istanbul ignore next */
if (!module.parent) {
app.listen(4000);
console.log('Express started on port 3000');
console.log('Express started on port 4000');
}

View File

@@ -6,7 +6,7 @@ var db = require('../../db');
exports.before = function(req, res, next){
var pet = db.pets[req.params.pet_id];
if (!pet) return next(new Error('Pet not found'));
if (!pet) return next('route');
req.pet = pet;
next();
};

View File

@@ -1,7 +1,6 @@
link(rel='stylesheet', href='/style.css')
h1= pet.name
form(action='/pet/#{pet.id}', method='post')
input(type='hidden', name='_method', value='put')
form(action='/pet/#{pet.id}?_method=put', method='post')
label= 'Name: '
input(type='text', name='pet[name]', value=pet.name)
input(type='submit', value='Update')

View File

@@ -11,7 +11,7 @@ exports.create = function(req, res, next){
var id = req.params.user_id;
var user = db.users[id];
var body = req.body;
if (!user) return next(new Error('User not found'));
if (!user) return next('route');
var pet = { name: body.pet.name };
pet.id = db.pets.push(pet) - 1;
user.pets.push(pet);

View File

@@ -11,7 +11,7 @@ exports.before = function(req, res, next){
process.nextTick(function(){
req.user = db.users[id];
// cant find that user
if (!req.user) return next(new Error('User not found'));
if (!req.user) return next('route');
// found it, move on to the routes
next();
});

View File

@@ -1,7 +1,6 @@
link(rel='stylesheet', href='/style.css')
h1= user.name
form(action='/user/#{user.id}', method='post')
input(type='hidden', name='_method', value='put')
form(action='/user/#{user.id}?_method=put', method='post')
label= 'Name: '
input(type='text', name='user[name]', value='#{user.name}')
input(type='submit', value='Update')

View File

@@ -5,7 +5,6 @@
var express = require('../..');
var logger = require('morgan');
var session = require('express-session');
var cookieParser = require('cookie-parser');
var bodyParser = require('body-parser');
var methodOverride = require('method-override');
@@ -38,14 +37,13 @@ if (!module.parent) app.use(logger('dev'));
app.use(express.static(__dirname + '/public'));
// session support
app.use(cookieParser('some secret here'));
app.use(session());
app.use(session({ secret: 'some secret here' }));
// parse request bodies (req.body)
app.use(bodyParser());
app.use(bodyParser.urlencoded({ extended: true }));
// override methods (put, delete)
app.use(methodOverride());
// allow overriding methods in query (?_method=put)
app.use(methodOverride('_method'));
// expose the "messages" local variable when views are rendered
app.use(function(req, res, next){
@@ -73,16 +71,9 @@ app.use(function(req, res, next){
// load controllers
require('./lib/boot')(app, { verbose: !module.parent });
// assume "not found" in the error msgs
// is a 404. this is somewhat silly, but
// valid, you can do whatever you like, set
// properties, use instanceof etc.
app.use(function(err, req, res, next){
// treat as 404
if (~err.message.indexOf('not found')) return next();
// log it
console.error(err.stack);
if (!module.parent) console.error(err.stack);
// error page
res.status(500).render('5xx');
@@ -93,7 +84,8 @@ app.use(function(req, res, next){
res.status(404).render('404', { url: req.originalUrl });
});
/* istanbul ignore next */
if (!module.parent) {
app.listen(3000);
console.log('\n listening on port 3000\n');
console.log('Express started on port 3000');
}

View File

@@ -13,6 +13,7 @@ module.exports = function(parent, options){
var name = obj.name || name;
var prefix = obj.prefix || '';
var app = express();
var handler;
var method;
var path;
@@ -20,16 +21,6 @@ module.exports = function(parent, options){
if (obj.engine) app.set('view engine', obj.engine);
app.set('views', __dirname + '/../controllers/' + name + '/views');
// before middleware support
if (obj.before) {
path = '/' + name + '/:' + name + '_id';
app.all(path, obj.before);
verbose && console.log(' ALL %s -> before', path);
path = '/' + name + '/:' + name + '_id/*';
app.all(path, obj.before);
verbose && console.log(' ALL %s -> before', path);
}
// generate routes based
// on the exported methods
for (var key in obj) {
@@ -62,15 +53,25 @@ module.exports = function(parent, options){
path = '/';
break;
default:
/* istanbul ignore next */
throw new Error('unrecognized route: ' + name + '.' + key);
}
// setup
handler = obj[key];
path = prefix + path;
app[method](path, obj[key]);
verbose && console.log(' %s %s -> %s', method.toUpperCase(), path, key);
// before middleware support
if (obj.before) {
app[method](path, obj.before, handler);
verbose && console.log(' %s %s -> before -> %s', method.toUpperCase(), path, key);
} else {
app[method](path, obj[key]);
verbose && console.log(' %s %s -> %s', method.toUpperCase(), path, key);
}
}
// mount the app
parent.use(app);
});
};
};

View File

@@ -49,5 +49,8 @@ app.get('/', function(req, res, next){
});
});
app.listen(3000);
console.log('listening on port 3000');
/* istanbul ignore next */
if (!module.parent) {
app.listen(3000);
console.log('Express started on port 3000');
}

View File

@@ -18,8 +18,8 @@ var users = [
// Convert :to and :from to integers
app.param(['to', 'from'], function(req, res, next, num, name){
req.params[name] = num = parseInt(num, 10);
if( isNaN(num) ){
req.params[name] = parseInt(num, 10);
if( isNaN(req.params[name]) ){
next(new Error('failed to parseInt '+num));
} else {
next();
@@ -63,7 +63,8 @@ app.get('/users/:from-:to', function(req, res, next){
res.send('users ' + names.slice(from, to).join(', '));
});
/* istanbul ignore next */
if (!module.parent) {
app.listen(3000);
console.log('Express started on port 3000');
}
}

View File

@@ -17,7 +17,10 @@ app.resource = function(path, obj) {
obj.range(req, res, a, b, format);
});
this.get(path + '/:id', obj.show);
this.delete(path + '/:id', obj.destroy);
this.delete(path + '/:id', function(req, res){
var id = parseInt(req.params.id, 10);
obj.destroy(req, res, id);
});
};
// Fake records
@@ -40,8 +43,7 @@ var User = {
show: function(req, res){
res.send(users[req.params.id] || { error: 'Cannot find user' });
},
destroy: function(req, res){
var id = req.params.id;
destroy: function(req, res, id){
var destroyed = id in users;
delete users[id];
res.send(destroyed ? 'destroyed' : 'Cannot find user');
@@ -84,7 +86,8 @@ app.get('/', function(req, res){
].join('\n'));
});
/* istanbul ignore next */
if (!module.parent) {
app.listen(3000);
console.log('Express started on port 3000');
}
}

View File

@@ -65,4 +65,8 @@ app.map({
}
});
app.listen(3000);
/* istanbul ignore next */
if (!module.parent) {
app.listen(3000);
console.log('Express started on port 3000');
}

View File

@@ -81,5 +81,8 @@ app.delete('/user/:id', loadUser, andRestrictTo('admin'), function(req, res){
res.send('Deleted user ' + req.user.name);
});
app.listen(3000);
console.log('Express app started on port 3000');
/* istanbul ignore next */
if (!module.parent) {
app.listen(3000);
console.log('Express started on port 3000');
}

View File

@@ -16,8 +16,9 @@ var user = require('./user');
app.set('view engine', 'jade');
app.set('views', __dirname + '/views');
app.use(logger('dev'));
app.use(methodOverride('_method'));
app.use(cookieParser());
app.use(bodyParser());
app.use(bodyParser.urlencoded({ extended: true }));
app.use(express.static(__dirname + '/public'));
// General
@@ -37,5 +38,8 @@ app.put('/user/:id/edit', user.update);
app.get('/posts', post.list);
app.listen(3000);
console.log('Express app started on port 3000');
/* istanbul ignore next */
if (!module.parent) {
app.listen(3000);
console.log('Express started on port 3000');
}

View File

@@ -3,8 +3,7 @@ extends ../layout
block content
h1 Editing #{user.name}
#user
form(method="post")
input(type="hidden", value="put", name="_method")
form(action="?_method=put", method="post")
p Name:
input(type="text", value= user.name, name="user[name]")
p Email:

View File

@@ -57,5 +57,8 @@ app.get('/client.js', function(req, res){
res.sendfile(__dirname + '/client.js');
});
app.listen(3000);
console.log('app listening on port 3000');
/* istanbul ignore next */
if (!module.parent) {
app.listen(3000);
console.log('Express started on port 3000');
}

View File

@@ -3,18 +3,12 @@
// $ redis-server
var express = require('../..');
var cookieParser = require('cookie-parser');
var session = require('express-session');
var app = express();
// Required by session() middleware
// pass the secret for signed cookies
// (required by session())
app.use(cookieParser('keyboard cat'));
// Populates req.session
app.use(session());
app.use(session({ secret: 'keyboard cat' }));
app.get('/', function(req, res){
var body = '';
@@ -27,5 +21,8 @@ app.get('/', function(req, res){
res.send(body + '<p>viewed <strong>' + req.session.views + '</strong> times.</p>');
});
app.listen(3000);
console.log('Express app started on port 3000');
/* istanbul ignore next */
if (!module.parent) {
app.listen(3000);
console.log('Express started on port 3000');
}

View File

@@ -4,7 +4,6 @@
var express = require('../..');
var logger = require('morgan');
var cookieParser = require('cookie-parser');
var session = require('express-session');
// pass the express to the connect redis module
@@ -15,13 +14,8 @@ var app = express();
app.use(logger('dev'));
// Required by session() middleware
// pass the secret for signed cookies
// (required by session())
app.use(cookieParser('keyboard cat'));
// Populates req.session
app.use(session({ store: new RedisStore }));
app.use(session({ store: new RedisStore, secret: 'keyboard cat' }));
app.get('/', function(req, res){
var body = '';

View File

@@ -18,7 +18,7 @@ edit /etc/hosts:
var main = express();
main.use(logger('dev'));
if (!module.parent) main.use(logger('dev'));
main.get('/', function(req, res){
res.send('Hello from main app!');
@@ -32,17 +32,20 @@ main.get('/:sub', function(req, res){
var redirect = express();
redirect.all('*', function(req, res){
console.log(req.subdomains);
res.redirect('http://example.com:3000/' + req.subdomains[0]);
redirect.use(function(req, res){
if (!module.parent) console.log(req.vhost);
res.redirect('http://example.com:3000/' + req.vhost[0]);
});
// Vhost app
var app = express();
var app = module.exports = express();
app.use(vhost('*.example.com', redirect)); // Serves all subdomains via Redirect app
app.use(vhost('example.com', main)); // Serves top level domain via Main server app
app.listen(3000);
console.log('Express app started on port 3000');
/* istanbul ignore next */
if (!module.parent) {
app.listen(3000);
console.log('Express started on port 3000');
}

View File

@@ -40,6 +40,7 @@ app.get('/Readme.md', function(req, res){
res.render('Readme.md');
});
/* istanbul ignore next */
if (!module.parent) {
app.listen(3000);
console.log('Express started on port 3000');

View File

@@ -145,5 +145,8 @@ app.all('/api/*', function(req, res, next){
*/
app.listen(3000);
console.log('Application listening on port 3000');
/* istanbul ignore next */
if (!module.parent) {
app.listen(3000);
console.log('Express started on port 3000');
}

View File

@@ -103,7 +103,8 @@ app.use(function(req, res){
res.send(404, { error: "Lame, can't find that" });
});
/* istanbul ignore next */
if (!module.parent) {
app.listen(3000);
console.log('Express server listening on port 3000');
console.log('Express started on port 3000');
}

View File

@@ -11,8 +11,10 @@ var query = require('./middleware/query');
var debug = require('debug')('express:application');
var View = require('./view');
var http = require('http');
var compileETag = require('./utils').compileETag;
var compileTrust = require('./utils').compileTrust;
var deprecate = require('./utils').deprecate;
var resolve = require('path').resolve;
/**
* Application prototype.
@@ -46,7 +48,7 @@ app.init = function(){
app.defaultConfiguration = function(){
// default settings
this.enable('x-powered-by');
this.enable('etag');
this.set('etag', 'weak');
var env = process.env.NODE_ENV || 'development';
this.set('env', env);
this.set('subdomain offset', 2);
@@ -73,7 +75,7 @@ app.defaultConfiguration = function(){
// default configuration
this.set('view', View);
this.set('views', process.cwd() + '/views');
this.set('views', resolve('views'));
this.set('jsonp callback name', 'callback');
if (env === 'production') {
@@ -165,9 +167,6 @@ app.handle = function(req, res, done) {
* If the _fn_ parameter is an express app, then it will be
* mounted at the _route_ specified.
*
* @param {String|Function|Server} route
* @param {Function|Server} fn
* @return {app} for chaining
* @api public
*/
@@ -305,18 +304,27 @@ app.param = function(name, fn){
*/
app.set = function(setting, val){
if (1 == arguments.length) {
if (arguments.length === 1) {
// app.get(setting)
return this.settings[setting];
} else {
this.settings[setting] = val;
if (setting === 'trust proxy') {
debug('compile trust proxy %j', val);
this.set('trust proxy fn', compileTrust(val));
}
return this;
}
// set value
this.settings[setting] = val;
// trigger matched settings
switch (setting) {
case 'etag':
debug('compile etag %s', val);
this.set('etag fn', compileETag(val));
break;
case 'trust proxy':
debug('compile trust proxy %s', val);
this.set('trust proxy fn', compileTrust(val));
break;
}
return this;
};
/**

View File

@@ -2,23 +2,23 @@
* Module dependencies.
*/
var escapeHtml = require('escape-html');
var http = require('http');
var path = require('path');
var mixin = require('utils-merge');
var escapeHtml = require('escape-html');
var sign = require('cookie-signature').sign;
var normalizeType = require('./utils').normalizeType;
var normalizeTypes = require('./utils').normalizeTypes;
var setCharset = require('./utils').setCharset;
var contentDisposition = require('./utils').contentDisposition;
var deprecate = require('./utils').deprecate;
var etag = require('./utils').etag;
var statusCodes = http.STATUS_CODES;
var cookie = require('cookie');
var send = require('send');
var basename = path.basename;
var extname = path.extname;
var mime = send.mime;
var vary = require('vary');
/**
* Response prototype.
@@ -75,9 +75,6 @@ res.links = function(links){
* res.send(404, 'Sorry, cant find that');
* res.send(404);
*
* @param {Mixed} body or status
* @param {Mixed} body
* @return {ServerResponse}
* @api public
*/
@@ -125,21 +122,6 @@ res.send = function(body){
break;
}
// populate Content-Length
if (undefined !== body && !this.get('Content-Length')) {
this.set('Content-Length', len = Buffer.isBuffer(body)
? body.length
: Buffer.byteLength(body));
}
// ETag support
// TODO: W/ support
if (app.settings.etag && len && ('GET' == req.method || 'HEAD' == req.method)) {
if (!this.get('ETag')) {
this.set('ETag', etag(body));
}
}
// write strings in utf-8
if ('string' === typeof body) {
encoding = 'utf8';
@@ -151,6 +133,23 @@ res.send = function(body){
}
}
// populate Content-Length
if (undefined !== body && !this.get('Content-Length')) {
len = Buffer.isBuffer(body)
? body.length
: Buffer.byteLength(body, encoding);
this.set('Content-Length', len);
}
// ETag support
var etag = len !== undefined && app.get('etag fn');
if (etag && ('GET' === req.method || 'HEAD' === req.method)) {
if (!this.get('ETag')) {
etag = etag(body, encoding);
etag && this.set('ETag', etag);
}
}
// freshness
if (req.fresh) this.statusCode = 304;
@@ -178,9 +177,6 @@ res.send = function(body){
* res.json(500, 'oh noes!');
* res.json(404, 'I dont have that');
*
* @param {Mixed} obj or status
* @param {Mixed} obj
* @return {ServerResponse}
* @api public
*/
@@ -227,9 +223,6 @@ var jsonNumDeprecated = deprecate(res.json,
* res.jsonp(500, 'oh noes!');
* res.jsonp(404, 'I dont have that');
*
* @param {Mixed} obj or status
* @param {Mixed} obj
* @return {ServerResponse}
* @api public
*/
@@ -318,9 +311,6 @@ var jsonpNumDeprecated = deprecate(res.json,
* });
* });
*
* @param {String} path
* @param {Object|Function} options or fn
* @param {Function} fn
* @api public
*/
@@ -394,9 +384,6 @@ res.sendfile = function(path, options, fn){
*
* This method uses `res.sendfile()`.
*
* @param {String} path
* @param {String|Function} filename or fn
* @param {Function} fn
* @api public
*/
@@ -749,31 +736,12 @@ res.redirect = function(url){
*/
res.vary = function(field){
var self = this;
// nothing
// checks for back-compat
if (!field) return this;
if (Array.isArray(field) && !field.length) return this;
// array
if (Array.isArray(field)) {
field.forEach(function(field){
self.vary(field);
});
return;
}
vary(this, field);
var vary = this.get('Vary');
// append
if (vary) {
vary = vary.split(/ *, */);
if (!~vary.indexOf(field)) vary.push(field);
this.set('Vary', vary.join(', '));
return this;
}
// set
this.set('Vary', field);
return this;
};
@@ -787,9 +755,6 @@ res.vary = function(field){
* - `cache` boolean hinting to the engine it should cache
* - `filename` filename of the view being rendered
*
* @param {String} view
* @param {Object|Function} options or callback function
* @param {Function} fn
* @api public
*/

View File

@@ -226,9 +226,11 @@ proto.handle = function(req, res, done) {
// Trim off the part of the url that matches the route
// middleware (.use stuff) needs to have the path stripped
debug('trim prefix (%s) from url %s', removed, req.url);
removed = layerPath;
req.url = protohost + req.url.substr(protohost.length + removed.length);
if (removed.length) {
debug('trim prefix (%s) from url %s', layerPath, req.url);
req.url = protohost + req.url.substr(protohost.length + removed.length);
}
// Ensure leading slash
if (!fqdn && req.url[0] !== '/') {
@@ -245,15 +247,15 @@ proto.handle = function(req, res, done) {
debug('%s %s : %s', layer.handle.name || 'anonymous', layerPath, req.originalUrl);
var arity = layer.handle.length;
if (err) {
if (arity === 4) {
try {
if (err && arity === 4) {
layer.handle(err, req, res, next);
} else if (!err && arity < 4) {
layer.handle(req, res, next);
} else {
next(err);
}
} else if (arity < 4) {
layer.handle(req, res, next);
} else {
} catch (err) {
next(err);
}
}
@@ -320,11 +322,19 @@ proto.process_params = function(layer, called, req, res, done) {
}
// param previously called with same value or error occurred
if (paramCalled && (paramCalled.err || paramCalled.val === paramVal)) {
return param(paramCalled.err);
if (paramCalled && (paramCalled.error || paramCalled.match === paramVal)) {
// restore value
req.params[name] = paramCalled.value;
// next param
return param(paramCalled.error);
}
called[name] = paramCalled = { val: paramVal };
called[name] = paramCalled = {
error: null,
match: paramVal,
value: paramVal
};
try {
return paramCallback();
@@ -335,13 +345,20 @@ proto.process_params = function(layer, called, req, res, done) {
// single param callbacks
function paramCallback(err) {
if (err && paramCalled) {
var fn = paramCallbacks[paramIndex++];
// store updated value
paramCalled.value = req.params[key.name];
if (err) {
// store error
paramCalled.err = err;
paramCalled.error = err;
param(err);
return;
}
var fn = paramCallbacks[paramIndex++];
if (err || !fn) return param(err);
if (!fn) return param();
fn(req, res, paramCallback, paramVal, key.name);
}

View File

@@ -4,6 +4,7 @@
var mime = require('send').mime;
var crc32 = require('buffer-crc32');
var crypto = require('crypto');
var basename = require('path').basename;
var deprecate = require('util').deprecate;
var proxyaddr = require('proxy-addr');
@@ -38,15 +39,47 @@ exports.deprecate = function(fn, msg){
};
/**
* Return ETag for `body`.
* Return strong ETag for `body`.
*
* @param {String|Buffer} body
* @param {String} [encoding]
* @return {String}
* @api private
*/
exports.etag = function(body){
return '"' + crc32.signed(body) + '"';
exports.etag = function etag(body, encoding){
if (body.length === 0) {
// fast-path empty body
return '"1B2M2Y8AsgTpgAmY7PhCfg=="'
}
var hash = crypto
.createHash('md5')
.update(body, encoding)
.digest('base64')
return '"' + hash + '"'
};
/**
* Return weak ETag for `body`.
*
* @param {String|Buffer} body
* @param {String} [encoding]
* @return {String}
* @api private
*/
exports.wetag = function wetag(body, encoding){
if (body.length === 0) {
// fast-path empty body
return 'W/"0-0"'
}
var buf = Buffer.isBuffer(body)
? body
: new Buffer(body, encoding)
var len = buf.length
return 'W/"' + len.toString(16) + '-' + crc32.unsigned(buf) + '"'
};
/**
@@ -131,7 +164,7 @@ exports.contentDisposition = function(filename){
filename = basename(filename);
// if filename contains non-ascii characters, add a utf-8 version ala RFC 5987
ret = /[^\040-\176]/.test(filename)
? 'attachment; filename=' + encodeURI(filename) + '; filename*=UTF-8\'\'' + encodeURI(filename)
? 'attachment; filename="' + encodeURI(filename) + '"; filename*=UTF-8\'\'' + encodeURI(filename)
: 'attachment; filename="' + filename + '"';
}
@@ -164,6 +197,40 @@ function acceptParams(str, index) {
return ret;
}
/**
* Compile "etag" value to function.
*
* @param {Boolean|String|Function} val
* @return {Function}
* @api private
*/
exports.compileETag = function(val) {
var fn;
if (typeof val === 'function') {
return val;
}
switch (val) {
case true:
fn = exports.wetag;
break;
case false:
break;
case 'strong':
fn = exports.etag;
break;
case 'weak':
fn = exports.wetag;
break;
default:
throw new TypeError('unknown value for etag function: ' + val);
}
return fn;
}
/**
* Compile "proxy trust" value to function.
*

View File

@@ -1,37 +1,15 @@
{
"name": "express",
"description": "Sinatra inspired web development framework",
"version": "4.3.2",
"version": "4.4.4",
"author": "TJ Holowaychuk <tj@vision-media.ca>",
"contributors": [
{
"name": "TJ Holowaychuk",
"email": "tj@vision-media.ca"
},
{
"name": "Aaron Heckmann",
"email": "aaron.heckmann+github@gmail.com"
},
{
"name": "Ciaran Jessup",
"email": "ciaranj@gmail.com"
},
{
"name": "Douglas Christopher Wilson",
"email": "doug@somethingdoug.com"
},
{
"name": "Guillermo Rauch",
"email": "rauchg@gmail.com"
},
{
"name": "Jonathan Ong",
"email": "me@jongleberry.com"
},
{
"name": "Roman Shtylman",
"email": "shtylman+expressjs@gmail.com"
}
"Aaron Heckmann <aaron.heckmann+github@gmail.com>",
"Ciaran Jessup <ciaranj@gmail.com>",
"Douglas Christopher Wilson <doug@somethingdoug.com>",
"Guillermo Rauch <rauchg@gmail.com>",
"Jonathan Ong <me@jongleberry.com>",
"Roman Shtylman <shtylman+expressjs@gmail.com"
],
"keywords": [
"express",
@@ -44,46 +22,47 @@
"app",
"api"
],
"repository": "git://github.com/visionmedia/express",
"repository": "visionmedia/express",
"license": "MIT",
"dependencies": {
"accepts": "1.0.1",
"accepts": "~1.0.5",
"buffer-crc32": "0.2.3",
"debug": "1.0.2",
"escape-html": "1.0.1",
"methods": "1.0.1",
"parseurl": "1.0.1",
"proxy-addr": "1.0.0",
"proxy-addr": "1.0.1",
"range-parser": "1.0.0",
"type-is": "1.2.0",
"send": "0.4.3",
"serve-static": "1.2.3",
"type-is": "1.2.1",
"vary": "0.1.0",
"cookie": "0.1.2",
"buffer-crc32": "0.2.1",
"fresh": "0.2.2",
"methods": "1.0.0",
"send": "0.3.0",
"cookie-signature": "1.0.3",
"merge-descriptors": "0.0.2",
"utils-merge": "1.0.0",
"escape-html": "1.0.1",
"qs": "0.6.6",
"serve-static": "1.1.0",
"path-to-regexp": "0.1.2",
"debug": "0.8.1"
"path-to-regexp": "0.1.2"
},
"devDependencies": {
"after": "0.8.1",
"istanbul": "0.2.10",
"mocha": "~1.19.0",
"should": "~3.3.1",
"supertest": "~0.12.0",
"mocha": "~1.20.1",
"should": "~4.0.4",
"supertest": "~0.13.0",
"connect-redis": "~2.0.0",
"ejs": "~1.0.0",
"jade": "~0.35.0",
"jade": "~1.3.1",
"marked": "0.3.2",
"multiparty": "~3.2.4",
"hjs": "~0.0.6",
"body-parser": "1.2.2",
"cookie-parser": "1.1.0",
"express-session": "1.2.1",
"method-override": "1.0.2",
"body-parser": "~1.4.3",
"cookie-parser": "~1.3.1",
"express-session": "~1.5.0",
"method-override": "2.0.2",
"morgan": "1.1.1",
"vhost": "1.0.0"
"vhost": "2.0.0"
},
"engines": {
"node": ">= 0.10.0"

View File

@@ -167,5 +167,24 @@ describe('Route', function(){
route.dispatch({ method: 'get' }, {});
});
it('should handle throwing inside error handlers', function(done) {
var route = new Route('');
route.get(function(req, res, next){
throw new Error('boom!');
});
route.get(function(err, req, res, next){
throw new Error('oops');
});
route.get(function(err, req, res, next){
assert.equal(err.message, 'oops');
done();
});
route.dispatch({ url: '/', method: 'GET' }, {}, done);
});
})
})

View File

@@ -129,7 +129,48 @@ describe('Router', function(){
done();
});
router.handle({ url: '/foo/2', method: 'GET' }, {}, done);
router.handle({ url: '/foo/2', method: 'GET' }, {}, function() {});
});
it('should handle throwing in handler after async param', function(done) {
var router = new Router();
router.param('user', function(req, res, next, val){
process.nextTick(function(){
req.user = val;
next();
});
});
router.use('/:user', function(req, res, next){
throw new Error('oh no!');
});
router.use(function(err, req, res, next){
assert.equal(err.message, 'oh no!');
done();
});
router.handle({ url: '/bob', method: 'GET' }, {}, function() {});
});
it('should handle throwing inside error handlers', function(done) {
var router = new Router();
router.use(function(req, res, next){
throw new Error('boom!');
});
router.use(function(err, req, res, next){
throw new Error('oops');
});
router.use(function(err, req, res, next){
assert.equal(err.message, 'oops');
done();
});
router.handle({ url: '/', method: 'GET' }, {}, done);
});
})

View File

@@ -22,6 +22,7 @@ describe('cookies', function(){
it('should respond to cookie', function(done){
request(app)
.post('/')
.type('urlencoded')
.send({ remember: 1 })
.expect(302, function(err, res){
if (err) return done(err)
@@ -37,6 +38,7 @@ describe('cookies', function(){
it('should clear cookie', function(done){
request(app)
.post('/')
.type('urlencoded')
.send({ remember: 1 })
.expect(302, function(err, res){
if (err) return done(err)
@@ -53,6 +55,7 @@ describe('cookies', function(){
it('should set a cookie', function(done){
request(app)
.post('/')
.type('urlencoded')
.send({ remember: 1 })
.expect(302, function(err, res){
res.headers.should.have.property('set-cookie')

View File

@@ -30,4 +30,4 @@ describe('downloads', function(){
.expect(404, done)
})
})
})
})

View File

@@ -7,14 +7,11 @@ describe('ejs', function(){
it('should respond with html', function(done){
request(app)
.get('/')
.end(function(err, res){
res.should.have.status(200);
res.should.have.header('Content-Type', 'text/html; charset=utf-8');
res.text.should.include('<li>tobi &lt;tobi@learnboost.com&gt;</li>');
res.text.should.include('<li>loki &lt;loki@learnboost.com&gt;</li>');
res.text.should.include('<li>jane &lt;jane@learnboost.com&gt;</li>');
done();
});
.expect('Content-Type', 'text/html; charset=utf-8')
.expect(/<li>tobi &lt;tobi@learnboost\.com&gt;<\/li>/)
.expect(/<li>loki &lt;loki@learnboost\.com&gt;<\/li>/)
.expect(/<li>jane &lt;jane@learnboost\.com&gt;<\/li>/)
.expect(200, done)
})
})
})
})

View File

@@ -1,6 +1,6 @@
var app = require('../../examples/markdown')
, request = require('supertest');
var request = require('supertest')
describe('markdown', function(){
describe('GET /', function(){
@@ -18,4 +18,4 @@ describe('markdown', function(){
.expect(500,done)
})
})
})
})

View File

@@ -33,6 +33,7 @@ describe('mvc', function(){
it('should update the pet', function(done){
request(app)
.put('/pet/3')
.set('Content-Type', 'application/x-www-form-urlencoded')
.send({ pet: { name: 'Boots' } })
.end(function(err, res){
if (err) return done(err);
@@ -47,13 +48,11 @@ describe('mvc', function(){
it('should display a list of users', function(done){
request(app)
.get('/users')
.end(function(err, res){
res.text.should.include('<h1>Users</h1>');
res.text.should.include('>TJ<');
res.text.should.include('>Guillermo<');
res.text.should.include('>Nathan<');
done();
})
.expect(/<h1>Users<\/h1>/)
.expect(/>TJ</)
.expect(/>Guillermo</)
.expect(/>Nathan</)
.expect(200, done)
})
})
@@ -62,21 +61,16 @@ describe('mvc', function(){
it('should display the user', function(done){
request(app)
.get('/user/0')
.end(function(err, res){
res.text.should.include('<h1>TJ <a href="/user/0/edit">edit');
done();
})
.expect(200, /<h1>TJ <a href="\/user\/0\/edit">edit/, done)
})
it('should display the users pets', function(done){
request(app)
.get('/user/0')
.end(function(err, res){
res.text.should.include('/pet/0">Tobi');
res.text.should.include('/pet/1">Loki');
res.text.should.include('/pet/2">Jane');
done();
})
.expect(/\/pet\/0">Tobi/)
.expect(/\/pet\/1">Loki/)
.expect(/\/pet\/2">Jane/)
.expect(200, done)
})
})
@@ -99,9 +93,17 @@ describe('mvc', function(){
})
describe('PUT /user/:id', function(){
it('should 500 on error', function(done){
request(app)
.put('/user/1')
.send({})
.expect(500, done)
})
it('should update the user', function(done){
request(app)
.put('/user/1')
.set('Content-Type', 'application/x-www-form-urlencoded')
.send({ user: { name: 'Tobo' }})
.end(function(err, res){
if (err) return done(err);
@@ -116,6 +118,7 @@ describe('mvc', function(){
it('should create a pet for user', function(done){
request(app)
.post('/user/2/pet')
.set('Content-Type', 'application/x-www-form-urlencoded')
.send({ pet: { name: 'Snickers' }})
.expect('Location', '/user/2')
.expect(302, function(err, res){

View File

@@ -1,5 +1,5 @@
var app = require('../../examples/params/app')
, request = require('supertest');
var request = require('supertest')
describe('params', function(){
describe('GET /', function(){
@@ -18,6 +18,14 @@ describe('params', function(){
})
})
describe('GET /user/9', function(){
it('should fail to find user', function(done){
request(app)
.get('/user/9')
.expect(/failed to find user/,done)
})
})
describe('GET /users/0-2', function(){
it('should respond with three users', function(done){
request(app)
@@ -25,4 +33,12 @@ describe('params', function(){
.expect(/users tj, tobi/,done)
})
})
})
describe('GET /users/foo-bar', function(){
it('should fail integer parsing', function(done){
request(app)
.get('/users/foo-bar')
.expect(/failed to parseInt foo/,done)
})
})
})

View File

@@ -1,5 +1,5 @@
var app = require('../../examples/resource/app')
, request = require('supertest');
var request = require('supertest')
describe('resource', function(){
describe('GET /', function(){
@@ -26,6 +26,14 @@ describe('resource', function(){
})
})
describe('GET /users/9', function(){
it('should respond with error', function(done){
request(app)
.get('/users/9')
.expect('{"error":"Cannot find user"}', done)
})
})
describe('GET /users/1..3', function(){
it('should respond with users 1 through 3', function(done){
request(app)
@@ -35,13 +43,21 @@ describe('resource', function(){
})
describe('DELETE /users/1', function(){
it('should respond with users 1 through 3', function(done){
it('should delete user 1', function(done){
request(app)
.del('/users/1')
.expect(/^destroyed/,done)
})
})
describe('DELETE /users/9', function(){
it('should fail', function(done){
request(app)
.del('/users/9')
.expect('Cannot find user', done)
})
})
describe('GET /users/1..3.json', function(){
it('should respond with users 2 and 3 as json', function(done){
request(app)
@@ -49,4 +65,4 @@ describe('resource', function(){
.expect(/^\[null,{"name":"aaron"},{"name":"guillermo"}\]/,done)
})
})
})
})

46
test/acceptance/vhost.js Normal file
View File

@@ -0,0 +1,46 @@
var app = require('../../examples/vhost')
var request = require('supertest')
describe('vhost', function(){
describe('example.com', function(){
describe('GET /', function(){
it('should say hello', function(done){
request(app)
.get('/')
.set('Host', 'example.com')
.expect(200, /hello/i, done)
})
})
describe('GET /foo', function(){
it('should say foo', function(done){
request(app)
.get('/foo')
.set('Host', 'example.com')
.expect(200, 'requested foo', done)
})
})
})
describe('foo.example.com', function(){
describe('GET /', function(){
it('should redirect to /foo', function(done){
request(app)
.get('/')
.set('Host', 'foo.example.com')
.expect(302, /Redirecting to http:\/\/example.com:3000\/foo/, done)
})
})
})
describe('bar.example.com', function(){
describe('GET /', function(){
it('should redirect to /bar', function(done){
request(app)
.get('/')
.set('Host', 'bar.example.com')
.expect(302, /Redirecting to http:\/\/example.com:3000\/bar/, done)
})
})
})
})

View File

@@ -98,12 +98,8 @@ describe('web-service', function(){
it('should respond with 404 json', function(done){
request(app)
.get('/api/something?api-key=bar')
.end(function(err, res){
res.should.have.status(404);
res.should.be.json;
res.text.should.equal('{"error":"Lame, can\'t find that"}');
done();
});
.expect('Content-Type', /json/)
.expect(404, '{"error":"Lame, can\'t find that"}', done)
})
})
})

View File

@@ -157,6 +157,44 @@ describe('app', function(){
.expect('2 2 foo,bob', done);
})
it('should support altering req.params across routes', function(done) {
var app = express();
app.param('user', function(req, res, next, user) {
req.params.user = 'loki';
next();
});
app.get('/:user', function(req, res, next) {
next('route');
});
app.get('/:user', function(req, res, next) {
res.send(req.params.user);
});
request(app)
.get('/bob')
.expect('loki', done);
})
it('should work with encoded values', function(done){
var app = express();
app.param('name', function(req, res, next, name){
req.params.name = name;
next();
});
app.get('/user/:name', function(req, res){
var name = req.params.name;
res.send('' + name);
});
request(app)
.get('/user/foo%25bar')
.expect('foo%bar', done);
})
it('should catch thrown error', function(done){
var app = express();

View File

@@ -49,4 +49,14 @@ describe('app.route', function(){
.get('/test')
.expect('test', done);
});
it('should not error on empty routes', function(done){
var app = express();
app.route('/:foo');
request(app)
.get('/test')
.expect(404, done);
});
});

View File

@@ -25,6 +25,11 @@ describe('app.router', function(){
[method]('/foo')
.expect('head' == method ? '' : method, done);
})
it('should reject numbers for app.' + method, function(){
var app = express();
app[method].bind(app, '/', 3).should.throw(/Number/);
})
});
})
@@ -534,6 +539,30 @@ describe('app.router', function(){
})
})
describe('when next("route") is called', function(){
it('should jump to next route', function(done){
var app = express()
function fn(req, res, next){
res.set('X-Hit', '1')
next('route')
}
app.get('/foo', fn, function(req, res, next){
res.end('failure')
});
app.get('/foo', function(req, res){
res.end('success')
})
request(app)
.get('/foo')
.expect('X-Hit', '1')
.expect(200, 'success', done)
})
})
describe('when next(err) is called', function(){
it('should break out of app.router', function(done){
var app = express()

View File

@@ -15,6 +15,11 @@ describe('app', function(){
app.use(blog);
})
it('should reject numbers', function(){
var app = express();
app.use.bind(app, 3).should.throw(/Number/);
})
describe('.use(app)', function(){
it('should mount the app', function(done){
var blog = express()

View File

@@ -13,6 +13,29 @@ describe('config', function(){
var app = express();
app.set('foo', undefined).should.equal(app);
})
describe('"etag"', function(){
it('should throw on bad value', function(){
var app = express()
app.set.bind(app, 'etag', 42).should.throw(/unknown value/)
})
it('should set "etag fn"', function(){
var app = express()
var fn = function(){}
app.set('etag', fn)
app.get('etag fn').should.equal(fn)
})
})
describe('"trust proxy"', function(){
it('should set "trust proxy fn"', function(){
var app = express()
var fn = function(){}
app.set('trust proxy', fn)
app.get('trust proxy fn').should.equal(fn)
})
})
})
describe('.get()', function(){
@@ -91,4 +114,4 @@ describe('config', function(){
app.disabled('foo').should.be.false;
})
})
})
})

View File

@@ -1,7 +1,7 @@
var express = require('../');
var request = require('supertest');
var assert = require('assert');
var should = require('should');
describe('exports', function(){
it('should expose Router', function(){
@@ -50,4 +50,12 @@ describe('exports', function(){
.get('/')
.expect('bar', done);
})
it('should throw on old middlewares', function(){
var error;
try { express.bodyParser; } catch (e) { error = e; }
should(error).have.property('message');
error.message.should.containEql('middleware');
error.message.should.containEql('bodyParser');
})
})

View File

@@ -6,15 +6,16 @@ describe('req', function(){
describe('.fresh', function(){
it('should return true when the resource is not modified', function(done){
var app = express();
var etag = '"12345"';
app.use(function(req, res){
res.set('ETag', '12345');
res.set('ETag', etag);
res.send(req.fresh);
});
request(app)
.get('/')
.set('If-None-Match', '12345')
.set('If-None-Match', etag)
.expect(304, done);
})
@@ -22,14 +23,14 @@ describe('req', function(){
var app = express();
app.use(function(req, res){
res.set('ETag', '123');
res.set('ETag', '"123"');
res.send(req.fresh);
});
request(app)
.get('/')
.set('If-None-Match', '12345')
.expect('false', done);
.set('If-None-Match', '"12345"')
.expect(200, 'false', done);
})
})
})

View File

@@ -34,7 +34,7 @@ describe('req', function(){
it('should check req.body', function(done){
var app = express();
app.use(bodyParser());
app.use(bodyParser.json());
app.use(function(req, res){
res.end(req.param('name'));

View File

@@ -6,15 +6,16 @@ describe('req', function(){
describe('.stale', function(){
it('should return false when the resource is not modified', function(done){
var app = express();
var etag = '"12345"';
app.use(function(req, res){
res.set('ETag', '12345');
res.set('ETag', etag);
res.send(req.stale);
});
request(app)
.get('/')
.set('If-None-Match', '12345')
.set('If-None-Match', etag)
.expect(304, done);
})
@@ -22,14 +23,14 @@ describe('req', function(){
var app = express();
app.use(function(req, res){
res.set('ETag', '123');
res.set('ETag', '"123"');
res.send(req.stale);
});
request(app)
.get('/')
.set('If-None-Match', '12345')
.expect('true', done);
.set('If-None-Match', '"12345"')
.expect(200, 'true', done);
})
})
})

View File

@@ -57,7 +57,7 @@ describe('res', function(){
request(app)
.get('/')
.expect('Content-Disposition', 'attachment;' +
' filename=%E6%97%A5%E6%9C%AC%E8%AA%9E.txt;' +
' filename="%E6%97%A5%E6%9C%AC%E8%AA%9E.txt";' +
' filename*=UTF-8\'\'%E6%97%A5%E6%9C%AC%E8%AA%9E.txt',
done);
})

View File

@@ -91,7 +91,7 @@ describe('res', function(){
request(app)
.get('/')
.end(function(err, res){
res.headers['set-cookie'][0].should.not.include('Thu, 01 Jan 1970 00:00:01 GMT');
res.headers['set-cookie'][0].should.not.containEql('Thu, 01 Jan 1970 00:00:01 GMT');
done();
})
})
@@ -106,10 +106,7 @@ describe('res', function(){
request(app)
.get('/')
.end(function(err, res){
res.headers['set-cookie'][0].should.include('Max-Age=1');
done();
})
.expect('Set-Cookie', /Max-Age=1/, done)
})
it('should not mutate the options object', function(done){

View File

@@ -14,12 +14,9 @@ describe('res', function(){
request(app)
.get('/')
.end(function(err, res){
res.should.have.header('Content-Type', 'text/html; charset=UTF-8');
res.should.have.header('Content-Disposition', 'attachment; filename="user.html"');
res.text.should.equal('<p>{{user.name}}</p>');
done();
});
.expect('Content-Type', 'text/html; charset=UTF-8')
.expect('Content-Disposition', 'attachment; filename="user.html"')
.expect(200, '<p>{{user.name}}</p>', done)
})
})
@@ -33,11 +30,9 @@ describe('res', function(){
request(app)
.get('/')
.end(function(err, res){
res.should.have.header('Content-Type', 'text/html; charset=UTF-8');
res.should.have.header('Content-Disposition', 'attachment; filename="document"');
done();
});
.expect('Content-Type', 'text/html; charset=UTF-8')
.expect('Content-Disposition', 'attachment; filename="document"')
.expect(200, done)
})
})
@@ -52,10 +47,11 @@ describe('res', function(){
request(app)
.get('/')
.end(function(err, res){
res.should.have.header('Content-Type', 'text/html; charset=UTF-8');
res.should.have.header('Content-Disposition', 'attachment; filename="user.html"');
});
.expect('Content-Type', 'text/html; charset=UTF-8')
.expect('Content-Disposition', 'attachment; filename="user.html"')
.expect(200, function(err){
assert.ifError(err)
})
})
})
@@ -70,10 +66,11 @@ describe('res', function(){
request(app)
.get('/')
.end(function(err, res){
res.should.have.header('Content-Type', 'text/html; charset=UTF-8');
res.should.have.header('Content-Disposition', 'attachment; filename="document"');
});
.expect('Content-Type', 'text/html; charset=UTF-8')
.expect('Content-Disposition', 'attachment; filename="document"')
.expect(200, function(err){
assert.ifError(err)
})
})
})

View File

@@ -77,6 +77,24 @@ describe('res', function(){
test(app2);
})
describe('with parameters', function(){
var app = express();
app.use(function(req, res, next){
res.format({
'text/plain; charset=utf-8': function(){ res.send('hey') },
'text/html; foo=bar; bar=baz': function(){ res.send('<p>hey</p>') },
'application/json; q=0.5': function(){ res.send({ message: 'hey' }) }
});
});
app.use(function(err, req, res, next){
res.send(err.status, 'Supports: ' + err.types.join(', '));
});
test(app);
})
describe('given .default', function(){
it('should be invoked instead of auto-responding', function(done){
request(app3)

View File

@@ -13,11 +13,8 @@ describe('res', function(){
request(app)
.get('/')
.end(function(err, res){
res.statusCode.should.equal(302);
res.headers.should.have.property('location', 'http://google.com');
done();
})
.expect('location', 'http://google.com')
.expect(302, done)
})
})
@@ -159,12 +156,11 @@ describe('res', function(){
request(app)
.get('/')
.set('Accept', 'application/octet-stream')
.end(function(err, res){
res.should.have.status(302);
res.headers.should.have.property('location', 'http://google.com');
.expect('location', 'http://google.com')
.expect('content-length', '0')
.expect(302, '', function(err, res){
if (err) return done(err)
res.headers.should.not.have.property('content-type');
res.headers.should.have.property('content-length', '0');
res.text.should.equal('');
done();
})
})

View File

@@ -109,7 +109,7 @@ describe('res', function(){
request(app)
.get('/')
.expect('ETag', '"-1498647312"')
.expect('ETag', 'W/"7ff-2796319984"')
.end(done);
})
@@ -198,7 +198,7 @@ describe('res', function(){
request(app)
.get('/')
.expect('ETag', '"-1498647312"')
.expect('ETag', 'W/"7ff-2796319984"')
.end(done);
})
@@ -291,15 +291,16 @@ describe('res', function(){
it('should always check regardless of length', function(done){
var app = express();
var etag = '"asdf"';
app.use(function(req, res, next){
res.set('ETag', 'asdf');
res.set('ETag', etag);
res.send('hey');
});
request(app)
.get('/')
.set('If-None-Match', 'asdf')
.set('If-None-Match', etag)
.expect(304, done);
})
@@ -313,22 +314,23 @@ describe('res', function(){
request(app)
.get('/')
.set('If-None-Match', '"-1498647312"')
.set('If-None-Match', 'W/"7ff-2796319984"')
.expect(304, done);
})
it('should not perform freshness check unless 2xx or 304', function(done){
var app = express();
var etag = '"asdf"';
app.use(function(req, res, next){
res.status(500);
res.set('ETag', 'asdf');
res.set('ETag', etag);
res.send('hey');
});
request(app)
.get('/')
.set('If-None-Match', 'asdf')
.set('If-None-Match', etag)
.expect('hey')
.expect(500, done);
})
@@ -347,22 +349,35 @@ describe('res', function(){
describe('"etag" setting', function(){
describe('when enabled', function(){
it('should send ETag even when content-length < 1024', function(done){
it('should send ETag', function(done){
var app = express();
app.use(function(req, res){
res.send('kajdslfkasdf');
});
app.enable('etag');
request(app)
.get('/')
.end(function(err, res){
res.headers.should.have.property('etag');
done();
});
.expect('etag', 'W/"c-1525560792"', done)
})
it('should send ETag ', function(done){
it('should send ETag for empty string response', function(done){
var app = express()
app.use(function(req, res){
res.send('')
});
app.enable('etag')
request(app)
.get('/')
.expect('etag', 'W/"0-0"', done)
})
it('should send ETag for long response', function(done){
var app = express();
app.use(function(req, res){
@@ -370,13 +385,44 @@ describe('res', function(){
res.send(str);
});
app.enable('etag');
request(app)
.get('/')
.expect('etag', 'W/"7ff-2796319984"', done)
});
it('should not override ETag when manually set', function(done){
var app = express();
app.use(function(req, res){
res.set('etag', '"asdf"');
res.send(200);
});
app.enable('etag');
request(app)
.get('/')
.expect('etag', '"asdf"', done)
});
it('should not send ETag for res.send()', function(done){
var app = express()
app.use(function(req, res){
res.send()
});
app.enable('etag')
request(app)
.get('/')
.end(function(err, res){
res.headers.should.have.property('etag', '"-1498647312"');
res.headers.should.not.have.property('etag');
done();
});
});
})
})
});
describe('when disabled', function(){
@@ -404,17 +450,85 @@ describe('res', function(){
app.disable('etag');
app.use(function(req, res){
res.set('etag', 1);
res.set('etag', '"asdf"');
res.send(200);
});
request(app)
.get('/')
.end(function(err, res){
res.headers.should.have.property('etag');
done();
});
.expect('etag', '"asdf"', done)
});
});
describe('when "strong"', function(){
it('should send strong ETag', function(done){
var app = express()
app.set('etag', 'strong');
app.use(function(req, res){
res.send('hello, world!');
});
request(app)
.get('/')
.expect('etag', '"Otu60XkfuuPskIiUxJY4cA=="', done)
})
})
describe('when "weak"', function(){
it('should send weak ETag', function(done){
var app = express()
app.set('etag', 'weak');
app.use(function(req, res){
res.send('hello, world!');
});
request(app)
.get('/')
.expect('etag', 'W/"d-1486392595"', done)
})
})
describe('when a function', function(){
it('should send custom ETag', function(done){
var app = express()
app.set('etag', function(body, encoding){
body.should.equal('hello, world!')
encoding.should.equal('utf8')
return '"custom"'
});
app.use(function(req, res){
res.send('hello, world!');
});
request(app)
.get('/')
.expect('etag', '"custom"', done)
})
it('should not send falsy ETag', function(done){
var app = express()
app.set('etag', function(body, encoding){
return undefined
});
app.use(function(req, res){
res.send('hello, world!');
});
request(app)
.get('/')
.end(function(err, res){
res.headers.should.not.have.property('etag')
done();
})
})
})
})
})

View File

@@ -9,11 +9,7 @@ describe('res', function(){
var app = express();
app.use(function(req, res){
res.sendfile('test/fixtures/user.html', function(err){
assert(!err);
req.socket.listeners('error').should.have.length(1); // node's original handler
done();
});
res.sendfile('test/fixtures/user.html', done)
});
request(app)

View File

@@ -20,8 +20,8 @@ describe('res', function(){
it('should coerce to a string', function(){
res.headers = {};
res.set('ETag', 123);
res.get('ETag').should.equal('123');
res.set('X-Number', 123);
res.get('X-Number').should.equal('123');
})
})
@@ -41,8 +41,9 @@ describe('res', function(){
it('should coerce to an array of strings', function(){
res.headers = {};
res.set('ETag', [123, 456]);
JSON.stringify(res.get('ETag')).should.equal('["123","456"]');
res.set('X-Numbers', [123, 456]);
JSON.stringify(res.get('X-Numbers'))
.should.equal('["123","456"]');
})
it('should not set a charset of one is already set', function () {
@@ -72,8 +73,8 @@ describe('res', function(){
it('should coerce to a string', function(){
res.headers = {};
res.set({ ETag: 123 });
res.get('ETag').should.equal('123');
res.set({ 'X-Number': 123 });
res.get('X-Number').should.equal('123');
})
})
})

View File

@@ -2,24 +2,72 @@
var utils = require('../lib/utils')
, assert = require('assert');
describe('utils.etag(body)', function(){
describe('utils.deprecate(fn, msg)', function(){
var env
before(function(){
env = process.env.NODE_ENV
})
after(function(){
process.env.NODE_ENV = env
})
var str = 'Hello CRC';
var strUTF8 = '<!DOCTYPE html>\n<html>\n<head>\n</head>\n<body><p>自動販売</p></body></html>';
it('should pass-through fn in test environment', function(){
var fn = function(){}
process.env.NODE_ENV = 'test'
utils.deprecate(fn).should.equal(fn)
})
it('should return new fn in other environment', function(){
var fn = function(){}
process.env.NODE_ENV = ''
utils.deprecate(fn).should.not.equal(fn)
})
})
describe('utils.etag(body, encoding)', function(){
it('should support strings', function(){
utils.etag(str).should.eql('"-2034458343"');
utils.etag('express!')
.should.eql('"zZdv4imtWD49AHEviejT6A=="')
})
it('should support utf8 strings', function(){
utils.etag(strUTF8).should.eql('"1395090196"');
utils.etag('express❤', 'utf8')
.should.eql('"fsFba4IxwQS6h6Umb+FNxw=="')
})
it('should support buffer', function(){
utils.etag(new Buffer(strUTF8)).should.eql('"1395090196"');
utils.etag(new Buffer(str)).should.eql('"-2034458343"');
var buf = new Buffer('express!')
utils.etag(buf)
.should.eql('"zZdv4imtWD49AHEviejT6A=="');
})
it('should support empty string', function(){
utils.etag('')
.should.eql('"1B2M2Y8AsgTpgAmY7PhCfg=="');
})
})
describe('utils.wetag(body, encoding)', function(){
it('should support strings', function(){
utils.wetag('express!')
.should.eql('W/"8-3098196679"')
})
it('should support utf8 strings', function(){
utils.wetag('express❤', 'utf8')
.should.eql('W/"a-1751845617"')
})
it('should support buffer', function(){
var buf = new Buffer('express!')
utils.wetag(buf)
.should.eql('W/"8-3098196679"');
})
it('should support empty string', function(){
utils.wetag('')
.should.eql('W/"0-0"');
})
})
describe('utils.isAbsolute()', function(){
@@ -28,7 +76,11 @@ describe('utils.isAbsolute()', function(){
assert(!utils.isAbsolute(':\\'));
})
it('should unices', function(){
it('should support windows unc', function(){
assert(utils.isAbsolute('\\\\foo\\bar'))
})
it('should support unices', function(){
assert(utils.isAbsolute('/foo/bar'));
assert(!utils.isAbsolute('foo/bar'));
})