1.0.0-dev

This commit is contained in:
thosakwe 2016-12-04 21:48:35 -05:00
parent 2137470d79
commit 58d24f6f84
3 changed files with 20 additions and 4 deletions

View file

@ -26,6 +26,15 @@ bool _isOriginAllowed(String origin, allowedOrigin) {
RequestMiddleware cors([CorsOptions options]) { RequestMiddleware cors([CorsOptions options]) {
final opts = options ?? new CorsOptions(); final opts = options ?? new CorsOptions();
/*
print(opts.credentials);
print(opts.allowedHeaders);
print(opts.methods);
print(opts.exposedHeaders);
print(opts.maxAge);
print(opts.origin);
*/
return (RequestContext req, ResponseContext res) async { return (RequestContext req, ResponseContext res) async {
// Access-Control-Allow-Credentials // Access-Control-Allow-Credentials
if (opts.credentials == true) { if (opts.credentials == true) {
@ -35,6 +44,9 @@ RequestMiddleware cors([CorsOptions options]) {
// Access-Control-Allow-Headers // Access-Control-Allow-Headers
if (opts.allowedHeaders.isNotEmpty) { if (opts.allowedHeaders.isNotEmpty) {
res.header('Access-Control-Allow-Headers', opts.allowedHeaders.join(',')); res.header('Access-Control-Allow-Headers', opts.allowedHeaders.join(','));
} else {
res.header('Access-Control-Allow-Headers',
req.headers.value('Access-Control-Allow-Headers'));
} }
// Access-Control-Expose-Headers // Access-Control-Expose-Headers

View file

@ -55,7 +55,7 @@ class CorsOptions {
'PUT', 'PUT',
'PATCH', 'PATCH',
'POST', 'POST',
'DELETE˝' 'DELETE'
], ],
this.origin: '*', this.origin: '*',
this.preflightContinue: false, this.preflightContinue: false,

View file

@ -14,9 +14,11 @@ main() {
app = new Angel() app = new Angel()
..before.add(cors()) ..before.add(cors())
..post('/', (req, res) async { ..post('/', (req, res) async {
return res res.write('hello world');
..write('hello world') return false;
..end(); })
..all('*', () {
throw new AngelHttpException.NotFound();
}); });
server = await app.startServer(); server = await app.startServer();
@ -34,6 +36,8 @@ main() {
test('POST works', () async { test('POST works', () async {
final response = await client.post(url); final response = await client.post(url);
expect(response.statusCode, equals(200)); expect(response.statusCode, equals(200));
print('Response: ${response.body}');
print('Headers: ${response.headers}');
expect(response.headers['access-control-allow-origin'], equals('*')); expect(response.headers['access-control-allow-origin'], equals('*'));
}); });
} }