mirror of
https://github.com/expressjs/express.git
synced 2026-02-26 08:45:36 +00:00
Compare commits
16 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
33eaa8329c | ||
|
|
3c4fd57e51 | ||
|
|
a1e42ac33f | ||
|
|
ce7d7bfd8d | ||
|
|
9bd86cdddc | ||
|
|
0117464ac2 | ||
|
|
6f6eec7d8d | ||
|
|
a4e93c0fb8 | ||
|
|
e2ad0d3d6e | ||
|
|
763be5e631 | ||
|
|
c8526932f3 | ||
|
|
5cf29a3d29 | ||
|
|
18a3cc03ee | ||
|
|
ea5e254c7d | ||
|
|
060653bd4c | ||
|
|
c70db96b06 |
16
History.md
16
History.md
@@ -1,4 +1,20 @@
|
||||
|
||||
3.0.5 / 2012-12-19
|
||||
==================
|
||||
|
||||
* add throwing when a non-function is passed to a route
|
||||
* fix: explicitly remove Transfer-Encoding header from 204 and 304 responses
|
||||
* revert "add 'etag' option"
|
||||
|
||||
3.0.4 / 2012-12-05
|
||||
==================
|
||||
|
||||
* add 'etag' option to disable `res.send()` Etags
|
||||
* add escaping of urls in text/plain in `res.redirect()`
|
||||
for old browsers interpreting as html
|
||||
* change crc32 module for a more liberal license
|
||||
* update connect
|
||||
|
||||
3.0.3 / 2012-11-13
|
||||
==================
|
||||
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
|
||||
/**
|
||||
* Module dependencies.
|
||||
*/
|
||||
@@ -21,6 +20,7 @@ api.use(express.bodyParser());
|
||||
*/
|
||||
|
||||
api.all('*', function(req, res, next){
|
||||
if (!req.get('Origin')) return next();
|
||||
// use "*" here to accept any origin
|
||||
res.set('Access-Control-Allow-Origin', 'http://localhost:3000');
|
||||
res.set('Access-Control-Allow-Methods', 'GET, POST');
|
||||
|
||||
@@ -20,7 +20,7 @@ exports = module.exports = createApplication;
|
||||
* Framework version.
|
||||
*/
|
||||
|
||||
exports.version = '3.0.3';
|
||||
exports.version = '3.0.5';
|
||||
|
||||
/**
|
||||
* Expose mime.
|
||||
@@ -46,7 +46,7 @@ function createApplication() {
|
||||
|
||||
/**
|
||||
* Expose connect.middleware as express.*
|
||||
* for example `express.logger` etc.
|
||||
* for example `express.logger` etc.
|
||||
*/
|
||||
|
||||
for (var key in connect.middleware) {
|
||||
|
||||
@@ -141,6 +141,7 @@ res.send = function(body){
|
||||
if (204 == this.statusCode || 304 == this.statusCode) {
|
||||
this.removeHeader('Content-Type');
|
||||
this.removeHeader('Content-Length');
|
||||
this.removeHeader('Transfer-Encoding');
|
||||
body = '';
|
||||
}
|
||||
|
||||
@@ -656,7 +657,7 @@ res.redirect = function(url){
|
||||
// Support text/{plain,html} by default
|
||||
this.format({
|
||||
text: function(){
|
||||
body = statusCodes[status] + '. Redirecting to ' + url;
|
||||
body = statusCodes[status] + '. Redirecting to ' + encodeURI(url);
|
||||
},
|
||||
|
||||
html: function(){
|
||||
|
||||
@@ -243,11 +243,17 @@ Router.prototype.route = function(method, path, callbacks){
|
||||
// ensure path was given
|
||||
if (!path) throw new Error('Router#' + method + '() requires a path');
|
||||
|
||||
// ensure all callbacks are functions
|
||||
callbacks.forEach(function(fn){
|
||||
if ('function' == typeof fn) return;
|
||||
throw new Error('Router#' + method + '() requires all callbacks to be functions');
|
||||
});
|
||||
|
||||
// create the route
|
||||
debug('defined %s %s', method, path);
|
||||
var route = new Route(method, path, callbacks, {
|
||||
sensitive: this.caseSensitive
|
||||
, strict: this.strict
|
||||
sensitive: this.caseSensitive,
|
||||
strict: this.strict
|
||||
});
|
||||
|
||||
// add it
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
*/
|
||||
|
||||
var mime = require('connect').mime
|
||||
, crc = require('crc');
|
||||
, crc32 = require('buffer-crc32');
|
||||
|
||||
/**
|
||||
* Return ETag for `body`.
|
||||
@@ -15,9 +15,7 @@ var mime = require('connect').mime
|
||||
*/
|
||||
|
||||
exports.etag = function(body){
|
||||
return '"' + (Buffer.isBuffer(body)
|
||||
? crc.buffer.crc32(body)
|
||||
: crc.crc32(body)) + '"';
|
||||
return '"' + crc32.signed(body) + '"';
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
10
package.json
10
package.json
@@ -1,21 +1,21 @@
|
||||
{
|
||||
"name": "express",
|
||||
"description": "Sinatra inspired web development framework",
|
||||
"version": "3.0.3",
|
||||
"version": "3.0.5",
|
||||
"author": "TJ Holowaychuk <tj@vision-media.ca>",
|
||||
"contributors": [
|
||||
{ "name": "TJ Holowaychuk", "email": "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": "Guillermo Rauch", "email": "rauchg@gmail.com" }
|
||||
],
|
||||
"dependencies": {
|
||||
"connect": "2.7.0",
|
||||
"connect": "2.7.1",
|
||||
"commander": "0.6.1",
|
||||
"range-parser": "0.0.4",
|
||||
"mkdirp": "0.3.3",
|
||||
"cookie": "0.0.5",
|
||||
"crc": "0.2.0",
|
||||
"buffer-crc32": "0.1.1",
|
||||
"fresh": "0.1.0",
|
||||
"methods": "0.0.1",
|
||||
"send": "0.1.0",
|
||||
|
||||
@@ -76,4 +76,28 @@ describe('Router', function(){
|
||||
.expect('foo', done);
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe('.multiple callbacks', function(){
|
||||
it('should throw if a callback is null', function(){
|
||||
assert.throws(function () {
|
||||
router.route('get', '/foo', null, function(){});
|
||||
})
|
||||
})
|
||||
|
||||
it('should throw if a callback is undefined', function(){
|
||||
assert.throws(function () {
|
||||
router.route('get', '/foo', undefined, function(){});
|
||||
})
|
||||
})
|
||||
|
||||
it('should throw if a callback is not a function', function(){
|
||||
assert.throws(function () {
|
||||
router.route('get', '/foo', 'not a function', function(){});
|
||||
})
|
||||
})
|
||||
|
||||
it('should not throw if all callbacks are functions', function(){
|
||||
router.route('get', '/foo', function(){}, function(){});
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
@@ -287,6 +287,23 @@ describe('res', function(){
|
||||
done();
|
||||
})
|
||||
})
|
||||
|
||||
it('should encode the url', function(done){
|
||||
var app = express();
|
||||
|
||||
app.use(function(req, res){
|
||||
res.redirect('http://example.com/?param=<script>alert("hax");</script>');
|
||||
});
|
||||
|
||||
request(app)
|
||||
.get('/')
|
||||
.set('Host', 'http://example.com')
|
||||
.set('Accept', 'text/plain, */*')
|
||||
.end(function(err, res){
|
||||
res.text.should.equal('Moved Temporarily. Redirecting to http://example.com/?param=%3Cscript%3Ealert(%22hax%22);%3C/script%3E');
|
||||
done();
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe('when accepting neither text or html', function(){
|
||||
|
||||
@@ -206,11 +206,11 @@ describe('res', function(){
|
||||
})
|
||||
|
||||
describe('when .statusCode is 204', function(){
|
||||
it('should strip Content-* fields & body', function(done){
|
||||
it('should strip Content-* fields, Transfer-Encoding field, and body', function(done){
|
||||
var app = express();
|
||||
|
||||
app.use(function(req, res){
|
||||
res.status(204).send('foo');
|
||||
res.status(204).set('Transfer-Encoding', 'chunked').send('foo');
|
||||
});
|
||||
|
||||
request(app)
|
||||
@@ -218,6 +218,7 @@ describe('res', function(){
|
||||
.end(function(err, res){
|
||||
res.headers.should.not.have.property('content-type');
|
||||
res.headers.should.not.have.property('content-length');
|
||||
res.headers.should.not.have.property('transfer-encoding');
|
||||
res.text.should.equal('');
|
||||
done();
|
||||
})
|
||||
@@ -225,11 +226,11 @@ describe('res', function(){
|
||||
})
|
||||
|
||||
describe('when .statusCode is 304', function(){
|
||||
it('should strip Content-* fields & body', function(done){
|
||||
it('should strip Content-* fields, Transfer-Encoding field, and body', function(done){
|
||||
var app = express();
|
||||
|
||||
app.use(function(req, res){
|
||||
res.status(304).send('foo');
|
||||
res.status(304).set('Transfer-Encoding', 'chunked').send('foo');
|
||||
});
|
||||
|
||||
request(app)
|
||||
@@ -237,6 +238,7 @@ describe('res', function(){
|
||||
.end(function(err, res){
|
||||
res.headers.should.not.have.property('content-type');
|
||||
res.headers.should.not.have.property('content-length');
|
||||
res.headers.should.not.have.property('transfer-encoding');
|
||||
res.text.should.equal('');
|
||||
done();
|
||||
})
|
||||
|
||||
@@ -2,6 +2,26 @@
|
||||
var utils = require('../lib/utils')
|
||||
, assert = require('assert');
|
||||
|
||||
describe('utils.etag(body)', function(){
|
||||
|
||||
var str = 'Hello CRC';
|
||||
var strUTF8 = '<!DOCTYPE html>\n<html>\n<head>\n</head>\n<body><p>自動販売</p></body></html>';
|
||||
|
||||
it('should support strings', function(){
|
||||
utils.etag(str).should.eql('"-2034458343"');
|
||||
})
|
||||
|
||||
it('should support utf8 strings', function(){
|
||||
utils.etag(strUTF8).should.eql('"1395090196"');
|
||||
})
|
||||
|
||||
it('should support buffer', function(){
|
||||
utils.etag(new Buffer(strUTF8)).should.eql('"1395090196"');
|
||||
utils.etag(new Buffer(str)).should.eql('"-2034458343"');
|
||||
})
|
||||
|
||||
})
|
||||
|
||||
describe('utils.isAbsolute()', function(){
|
||||
it('should support windows', function(){
|
||||
assert(utils.isAbsolute('c:\\'));
|
||||
|
||||
Reference in New Issue
Block a user