Comparar commits
11 Commits
3.0.0beta1
...
3.0.0beta2
| Autor | SHA1 | Data | |
|---|---|---|---|
| 2787bd5bf0 | |||
| 6aaa7dc26d | |||
| ebf60d2340 | |||
| 02d43846f6 | |||
| 8930cd563c | |||
| 2b90cd7d51 | |||
| d5fde6a4b9 | |||
| 99b2e0fa08 | |||
| ebcb1ca90e | |||
| 1763b073f9 | |||
| 908e467548 |
@@ -1,4 +1,12 @@
|
||||
|
||||
3.0.0beta2 / 2012-06-06
|
||||
==================
|
||||
|
||||
* Added `+` support to the router
|
||||
* Added `req.host`
|
||||
* Changed `req.param()` to check route first
|
||||
* Update connect dep
|
||||
|
||||
3.0.0beta1 / 2012-06-01
|
||||
==================
|
||||
|
||||
|
||||
+1
-1
@@ -77,7 +77,7 @@ app.listen(3000);
|
||||
First install the dev dependencies to install all the example / test suite deps:
|
||||
|
||||
$ cd express
|
||||
$ npm install -d
|
||||
$ npm install
|
||||
|
||||
then run whichever tests you want:
|
||||
|
||||
|
||||
+1
-1
@@ -22,7 +22,7 @@ exports = module.exports = createApplication;
|
||||
* Framework version.
|
||||
*/
|
||||
|
||||
exports.version = '3.0.0beta1';
|
||||
exports.version = '3.0.0beta2';
|
||||
|
||||
/**
|
||||
* Create an express application.
|
||||
|
||||
+18
-25
@@ -208,8 +208,8 @@ req.__defineGetter__('acceptedCharsets', function(){
|
||||
/**
|
||||
* Return the value of param `name` when present or `defaultValue`.
|
||||
*
|
||||
* - Checks body params, ex: id=12, {"id":12}
|
||||
* - Checks route placeholders, ex: _/user/:id_
|
||||
* - Checks body params, ex: id=12, {"id":12}
|
||||
* - Checks query string params, ex: ?id=12
|
||||
*
|
||||
* To utilize request bodies, `req.body`
|
||||
@@ -223,19 +223,12 @@ req.__defineGetter__('acceptedCharsets', function(){
|
||||
*/
|
||||
|
||||
req.param = function(name, defaultValue){
|
||||
// req.body
|
||||
if (this.body && undefined !== this.body[name]) return this.body[name];
|
||||
|
||||
// route params
|
||||
if (this.params
|
||||
&& this.params.hasOwnProperty(name)
|
||||
&& undefined !== this.params[name]) {
|
||||
return this.params[name];
|
||||
}
|
||||
|
||||
// query-string
|
||||
if (undefined !== this.query[name]) return this.query[name];
|
||||
|
||||
var params = this.params || {};
|
||||
var body = this.body || {};
|
||||
var query = this.query || {};
|
||||
if (null != params[name] && params.hasOwnProperty(name)) return params[name];
|
||||
if (null != body[name]) return body[name];
|
||||
if (null != query[name]) return query[name];
|
||||
return defaultValue;
|
||||
};
|
||||
|
||||
@@ -260,17 +253,6 @@ req.param = function(name, defaultValue){
|
||||
* req.is('html');
|
||||
* // => false
|
||||
*
|
||||
* Now within our route callbacks, we can use to to assert content types
|
||||
* such as "image/jpeg", "image/png" as shown here:
|
||||
*
|
||||
* app.post('/image/upload', function(req, res, next){
|
||||
* if (req.is('image/*')) {
|
||||
* // do something
|
||||
* } else {
|
||||
* next();
|
||||
* }
|
||||
* });
|
||||
*
|
||||
* @param {String} type
|
||||
* @return {Boolean}
|
||||
* @api public
|
||||
@@ -386,6 +368,17 @@ req.__defineGetter__('path', function(){
|
||||
return parse(this).pathname;
|
||||
});
|
||||
|
||||
/**
|
||||
* Parse the "Host" header field hostname.
|
||||
*
|
||||
* @return {String}
|
||||
* @api public
|
||||
*/
|
||||
|
||||
req.__defineGetter__('host', function(){
|
||||
return this.get('Host').split(':')[0];
|
||||
});
|
||||
|
||||
/**
|
||||
* Check if the request is fresh, aka
|
||||
* Last-Modified and/or the ETag
|
||||
|
||||
+2
-2
@@ -12,6 +12,7 @@ var fs = require('fs')
|
||||
, normalizeTypes = require('./utils').normalizeTypes
|
||||
, statusCodes = http.STATUS_CODES
|
||||
, send = connect.static.send
|
||||
, cookie = require('cookie')
|
||||
, crc = require('crc')
|
||||
, mime = require('mime')
|
||||
, basename = path.basename
|
||||
@@ -481,8 +482,7 @@ res.cookie = function(name, val, options){
|
||||
if (signed) val = utils.sign(val, secret);
|
||||
if ('maxAge' in options) options.expires = new Date(Date.now() + options.maxAge);
|
||||
if (null == options.path) options.path = '/';
|
||||
var cookie = utils.serializeCookie(name, val, options);
|
||||
this.set('Set-Cookie', cookie);
|
||||
this.set('Set-Cookie', cookie.serialize(name, String(val), options));
|
||||
return this;
|
||||
};
|
||||
|
||||
|
||||
@@ -264,6 +264,7 @@ exports.pathRegexp = function(path, keys, sensitive, strict) {
|
||||
path = path
|
||||
.concat(strict ? '' : '/?')
|
||||
.replace(/\/\(/g, '(?:/')
|
||||
.replace(/\+/g, '__plus__')
|
||||
.replace(/(\/)?(\.)?:(\w+)(?:(\(.*?\)))?(\?)?/g, function(_, slash, format, key, capture, optional){
|
||||
keys.push({ name: key, optional: !! optional });
|
||||
slash = slash || '';
|
||||
@@ -275,6 +276,7 @@ exports.pathRegexp = function(path, keys, sensitive, strict) {
|
||||
+ (optional || '');
|
||||
})
|
||||
.replace(/([\/.])/g, '\\$1')
|
||||
.replace(/__plus__/g, '(.+)')
|
||||
.replace(/\*/g, '(.*)');
|
||||
return new RegExp('^' + path + '$', sensitive ? '' : 'i');
|
||||
}
|
||||
+3
-2
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "express",
|
||||
"description": "Sinatra inspired web development framework",
|
||||
"version": "3.0.0beta1",
|
||||
"version": "3.0.0beta2",
|
||||
"author": "TJ Holowaychuk <tj@vision-media.ca>",
|
||||
"contributors": [
|
||||
{ "name": "TJ Holowaychuk", "email": "tj@vision-media.ca" },
|
||||
@@ -10,10 +10,11 @@
|
||||
{ "name": "Guillermo Rauch", "email": "rauchg@gmail.com" }
|
||||
],
|
||||
"dependencies": {
|
||||
"connect": "2.3.0",
|
||||
"connect": "2.3.1",
|
||||
"commander": "0.6.1",
|
||||
"mime": "1.2.5",
|
||||
"mkdirp": "0.3.2",
|
||||
"cookie": "0.0.3",
|
||||
"crc": "0.2.0",
|
||||
"debug": "*"
|
||||
},
|
||||
|
||||
+23
-18
@@ -256,23 +256,6 @@ describe('app.router', function(){
|
||||
})
|
||||
})
|
||||
|
||||
it('should allow escaped regexp', function(done){
|
||||
var app = express();
|
||||
|
||||
app.get('/user/\\d+', function(req, res){
|
||||
res.end('woot');
|
||||
});
|
||||
|
||||
request(app)
|
||||
.get('/user/10')
|
||||
.end(function(res){
|
||||
res.statusCode.should.equal(200);
|
||||
request(app)
|
||||
.get('/user/tj')
|
||||
.expect(404, done);
|
||||
});
|
||||
})
|
||||
|
||||
it('should allow literal "."', function(done){
|
||||
var app = express();
|
||||
|
||||
@@ -288,10 +271,32 @@ describe('app.router', function(){
|
||||
.expect('users from 1 to 50', done);
|
||||
})
|
||||
|
||||
describe('*', function(){
|
||||
describe('+', function(){
|
||||
it('should denote a greedy capture group', function(done){
|
||||
var app = express();
|
||||
|
||||
app.get('/blog+', function(req, res){
|
||||
res.end(req.params[0] || 'nothing');
|
||||
});
|
||||
|
||||
request(app)
|
||||
.get('/blog')
|
||||
.expect(404, function(){
|
||||
request(app)
|
||||
.get('/blog/post')
|
||||
.expect(200, function(){
|
||||
request(app)
|
||||
.get('/blog-admin')
|
||||
.expect(200, done)
|
||||
})
|
||||
});
|
||||
})
|
||||
})
|
||||
|
||||
describe('*', function(){
|
||||
it('should denote an optional greedy capture group', function(done){
|
||||
var app = express();
|
||||
|
||||
app.get('/user/*.json', function(req, res){
|
||||
res.end(req.params[0]);
|
||||
});
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
|
||||
var express = require('../');
|
||||
|
||||
function req(ret) {
|
||||
return {
|
||||
get: function(){ return ret }
|
||||
, __proto__: express.request
|
||||
};
|
||||
}
|
||||
|
||||
describe('req', function(){
|
||||
describe('.host', function(){
|
||||
it('should return hostname', function(){
|
||||
req('example.com:3000').host.should.equal('example.com');
|
||||
req('example.com').host.should.equal('example.com');
|
||||
})
|
||||
})
|
||||
})
|
||||
+2
-2
@@ -59,13 +59,13 @@ describe('req', function(){
|
||||
var app = express();
|
||||
|
||||
app.get('/user/:name', function(req, res){
|
||||
res.end(req.param('name'));
|
||||
res.end(req.param('filter') + req.param('name'));
|
||||
});
|
||||
|
||||
request(app)
|
||||
.get('/user/tj')
|
||||
.end(function(res){
|
||||
res.body.should.equal('tj');
|
||||
res.body.should.equal('undefinedtj');
|
||||
done();
|
||||
})
|
||||
})
|
||||
|
||||
@@ -14,7 +14,7 @@ describe('res', function(){
|
||||
request(app)
|
||||
.get('/')
|
||||
.end(function(res){
|
||||
var val = 'sid=; path=/; expires=Thu, 01 Jan 1970 00:00:00 GMT';
|
||||
var val = 'sid=; Path=/; Expires=Thu, 01 Jan 1970 00:00:00 GMT';
|
||||
res.headers['set-cookie'].should.eql([val]);
|
||||
done();
|
||||
})
|
||||
@@ -32,7 +32,7 @@ describe('res', function(){
|
||||
request(app)
|
||||
.get('/')
|
||||
.end(function(res){
|
||||
var val = 'sid=; path=/admin; expires=Thu, 01 Jan 1970 00:00:00 GMT';
|
||||
var val = 'sid=; Path=/admin; Expires=Thu, 01 Jan 1970 00:00:00 GMT';
|
||||
res.headers['set-cookie'].should.eql([val]);
|
||||
done();
|
||||
})
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
|
||||
var express = require('../')
|
||||
, request = require('./support/http');
|
||||
, request = require('./support/http')
|
||||
, cookie = require('cookie');
|
||||
|
||||
describe('res', function(){
|
||||
describe('.cookie(name, object)', function(){
|
||||
@@ -14,7 +15,7 @@ describe('res', function(){
|
||||
request(app)
|
||||
.get('/')
|
||||
.end(function(res){
|
||||
var val = ['user=j%3A%7B%22name%22%3A%22tobi%22%7D; path=/'];
|
||||
var val = ['user=j:{%22name%22:%22tobi%22}; Path=/'];
|
||||
res.headers['set-cookie'].should.eql(val);
|
||||
done();
|
||||
})
|
||||
@@ -32,7 +33,7 @@ describe('res', function(){
|
||||
request(app)
|
||||
.get('/')
|
||||
.end(function(res){
|
||||
var val = ['name=tobi; path=/'];
|
||||
var val = ['name=tobi; Path=/'];
|
||||
res.headers['set-cookie'].should.eql(val);
|
||||
done();
|
||||
})
|
||||
@@ -50,7 +51,7 @@ describe('res', function(){
|
||||
request(app)
|
||||
.get('/')
|
||||
.end(function(res){
|
||||
var val = ['name=tobi; path=/', 'age=1; path=/'];
|
||||
var val = ['name=tobi; Path=/', 'age=1; Path=/'];
|
||||
res.headers['set-cookie'].should.eql(val);
|
||||
done();
|
||||
})
|
||||
@@ -69,7 +70,7 @@ describe('res', function(){
|
||||
request(app)
|
||||
.get('/')
|
||||
.end(function(res){
|
||||
var val = ['name=tobi; path=/; httpOnly; secure'];
|
||||
var val = ['name=tobi; Path=/; HttpOnly; Secure'];
|
||||
res.headers['set-cookie'].should.eql(val);
|
||||
done();
|
||||
})
|
||||
@@ -107,8 +108,8 @@ describe('res', function(){
|
||||
.get('/')
|
||||
.end(function(res){
|
||||
var val = res.headers['set-cookie'][0];
|
||||
val = decodeURIComponent(val.split('.')[0]);
|
||||
val.should.equal('user=j:{"name":"tobi"}');
|
||||
val = cookie.parse(val.split('.')[0]);
|
||||
val.user.should.equal('j:{"name":"tobi"}');
|
||||
done();
|
||||
})
|
||||
})
|
||||
@@ -127,7 +128,7 @@ describe('res', function(){
|
||||
request(app)
|
||||
.get('/')
|
||||
.end(function(res){
|
||||
var val = ['name=tobi.xJjV2iZ6EI7C8E5kzwbfA9PVLl1ZR07UTnuTgQQ4EnQ; path=/'];
|
||||
var val = ['name=tobi.xJjV2iZ6EI7C8E5kzwbfA9PVLl1ZR07UTnuTgQQ4EnQ; Path=/'];
|
||||
res.headers['set-cookie'].should.eql(val);
|
||||
done();
|
||||
})
|
||||
|
||||
Referência em uma Nova Issue
Bloquear um usuário