- app.listen()
- connect.basicAuth(user, pass)
- connect.basicAuth(callback)
- connect.basicAuth(callback) async
- connect.bodyParser()
- connect.compress()
- connect.cookieSession()
- exports
- connect.json()
- connect.limit()
- app.use()
- connect.multipart()
- patch
- connect.query()
- connect.responseTime()
- app
- connect.session()
- connect.static()
- connect.staticCache()
- connect.urlencoded()
- utils.uid(len)
- utils.parseCacheControl(str)
- utils.parseCookie(str)
- utils.serializeCookie(name, val[, options])
- utils.[un]sign()
- utils.parseRange(len, str)
- utils.mime(req)
- connect.vhost()
var app = connect();
app.use(function(req, res){
res.end();
});
app.listen(5555, function(){
app
.request('/')
.expect(200, done);
});
app.request()
.get('/')
.end(function(res){
res.statusCode.should.equal(401);
res.headers['www-authenticate'].should.equal('Basic realm="Authorization Required"');
done();
});
app.request()
.get('/')
.set('Authorization', 'Basic dGo6dG9iaQ==')
.end(function(res){
res.statusCode.should.equal(200);
res.body.should.equal('secret!');
done();
});
app.request()
.get('/')
.set('Authorization', 'Basic dGo69iaQ==')
.end(function(res){
res.statusCode.should.equal(401);
res.headers['www-authenticate'].should.equal('Basic realm="Authorization Required"');
res.body.should.equal('Unauthorized');
done();
});
app.request()
.get('/')
.end(function(res){
res.statusCode.should.equal(401);
res.headers['www-authenticate'].should.equal('Basic realm="Authorization Required"');
done();
});
app.request()
.get('/')
.set('Authorization', 'Basic dGo6dG9iaQ==')
.end(function(res){
res.statusCode.should.equal(200);
res.body.should.equal('secret!');
done();
});
app.request()
.get('/')
.set('Authorization', 'Basic dGo69iaQ==')
.end(function(res){
res.statusCode.should.equal(401);
res.headers['www-authenticate'].should.equal('Basic realm="Authorization Required"');
res.body.should.equal('Unauthorized');
done();
});
app.request()
.get('/')
.end(function(res){
res.statusCode.should.equal(401);
res.headers['www-authenticate'].should.equal('Basic realm="Authorization Required"');
done();
});
app.request()
.get('/')
.set('Authorization', 'Basic dGo6dG9iaQ==')
.end(function(res){
res.statusCode.should.equal(200);
res.body.should.equal('secret!');
done();
});
app.request()
.get('/')
.set('Authorization', 'Basic dGo69iaQ==')
.end(function(res){
res.statusCode.should.equal(401);
res.headers['www-authenticate'].should.equal('Basic realm="Authorization Required"');
res.body.should.equal('Unauthorized');
done();
});
app.request()
.post('/')
.end(function(res){
res.body.should.equal('{}');
done();
})
should parse JSON.
app.request()
.post('/')
.set('Content-Type', 'application/json')
.write('{"user":"tobi"}')
.end(function(res){
res.body.should.equal('{"user":"tobi"}');
done();
});
should parse x-www-form-urlencoded.
app.request()
.post('/')
.set('Content-Type', 'application/x-www-form-urlencoded')
.write('user=tobi')
.end(function(res){
res.body.should.equal('{"user":"tobi"}');
done();
});
app.request()
.post('/')
.set('Content-Type', 'multipart/form-data; boundary=foo')
.write('--foo\r\n')
.write('Content-Disposition: form-data; name="user"\r\n')
.write('\r\n')
.write('Tobi')
.write('\r\n--foo--')
.end(function(res){
res.body.should.equal('{"user":"Tobi"}');
done();
});
should support files.
var app = connect();
app.use(connect.bodyParser());
app.use(function(req, res){
req.body.user.should.eql({ name: 'Tobi' });
req.files.text.path.should.not.include('.txt');
req.files.text.constructor.name.should.equal('File');
res.end(req.files.text.name);
});
app.request()
.post('/')
.set('Content-Type', 'multipart/form-data; boundary=foo')
.write('--foo\r\n')
.write('Content-Disposition: form-data; name="user[name]"\r\n')
.write('\r\n')
.write('Tobi')
.write('\r\n--foo\r\n')
.write('Content-Disposition: form-data; name="text"; filename="foo.txt"\r\n')
.write('\r\n')
.write('some text here')
.write('\r\n--foo--')
.end(function(res){
res.body.should.equal('foo.txt');
done();
});
should expose options to formidable.
var app = connect();
app.use(connect.bodyParser({
keepExtensions: true
}));
app.use(function(req, res){
req.body.user.should.eql({ name: 'Tobi' });
req.files.text.path.should.include('.txt');
req.files.text.constructor.name.should.equal('File');
res.end(req.files.text.name);
});
app.request()
.post('/')
.set('Content-Type', 'multipart/form-data; boundary=foo')
.write('--foo\r\n')
.write('Content-Disposition: form-data; name="user[name]"\r\n')
.write('\r\n')
.write('Tobi')
.write('\r\n--foo\r\n')
.write('Content-Disposition: form-data; name="text"; filename="foo.txt"\r\n')
.write('\r\n')
.write('some text here')
.write('\r\n--foo--')
.end(function(res){
res.body.should.equal('foo.txt');
done();
});
should work with multiple fields.
app.request()
.post('/')
.set('Content-Type', 'multipart/form-data; boundary=foo')
.write('--foo\r\n')
.write('Content-Disposition: form-data; name="user"\r\n')
.write('\r\n')
.write('Tobi')
.write('\r\n--foo\r\n')
.write('Content-Disposition: form-data; name="age"\r\n')
.write('\r\n')
.write('1')
.write('\r\n--foo--')
.end(function(res){
res.body.should.equal('{"user":"Tobi","age":"1"}');
done();
});
should support nesting.
app.request()
.post('/')
.set('Content-Type', 'multipart/form-data; boundary=foo')
.write('--foo\r\n')
.write('Content-Disposition: form-data; name="user[name][first]"\r\n')
.write('\r\n')
.write('tobi')
.write('\r\n--foo\r\n')
.write('Content-Disposition: form-data; name="user[name][last]"\r\n')
.write('\r\n')
.write('holowaychuk')
.write('\r\n--foo\r\n')
.write('Content-Disposition: form-data; name="user[age]"\r\n')
.write('\r\n')
.write('1')
.write('\r\n--foo\r\n')
.write('Content-Disposition: form-data; name="species"\r\n')
.write('\r\n')
.write('ferret')
.write('\r\n--foo--')
.end(function(res){
var obj = JSON.parse(res.body);
obj.user.age.should.equal('1');
obj.user.name.should.eql({ first: 'tobi', last: 'holowaychuk' });
obj.species.should.equal('ferret');
done();
});
should support multiple files of the same name.
var app = connect();
app.use(connect.bodyParser());
app.use(function(req, res){
req.files.text.should.have.length(2);
req.files.text[0].constructor.name.should.equal('File');
req.files.text[1].constructor.name.should.equal('File');
res.end();
});
app.request()
.post('/')
.set('Content-Type', 'multipart/form-data; boundary=foo')
.write('--foo\r\n')
.write('Content-Disposition: form-data; name="text"; filename="foo.txt"\r\n')
.write('\r\n')
.write('some text here')
.write('\r\n--foo\r\n')
.write('Content-Disposition: form-data; name="text"; filename="bar.txt"\r\n')
.write('\r\n')
.write('some more text stuff')
.write('\r\n--foo--')
.end(function(res){
res.statusCode.should.equal(200);
done();
});
should support nested files.
var app = connect();
app.use(connect.bodyParser());
app.use(function(req, res){
Object.keys(req.files.docs).should.have.length(2);
req.files.docs.foo.name.should.equal('foo.txt');
req.files.docs.bar.name.should.equal('bar.txt');
res.end();
});
app.request()
.post('/')
.set('Content-Type', 'multipart/form-data; boundary=foo')
.write('--foo\r\n')
.write('Content-Disposition: form-data; name="docs[foo]"; filename="foo.txt"\r\n')
.write('\r\n')
.write('some text here')
.write('\r\n--foo\r\n')
.write('Content-Disposition: form-data; name="docs[bar]"; filename="bar.txt"\r\n')
.