diff --git a/.idea/misc.xml b/.idea/misc.xml
new file mode 100644
index 00000000..639900d1
--- /dev/null
+++ b/.idea/misc.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/modules.xml b/.idea/modules.xml
new file mode 100644
index 00000000..fde12639
--- /dev/null
+++ b/.idea/modules.xml
@@ -0,0 +1,8 @@
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/vcs.xml b/.idea/vcs.xml
new file mode 100644
index 00000000..35eb1ddf
--- /dev/null
+++ b/.idea/vcs.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/cors.iml b/cors.iml
new file mode 100644
index 00000000..5a5ced28
--- /dev/null
+++ b/cors.iml
@@ -0,0 +1,14 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/lib/angel_cors.dart b/lib/angel_cors.dart
index fc2619fa..1699a387 100644
--- a/lib/angel_cors.dart
+++ b/lib/angel_cors.dart
@@ -9,13 +9,14 @@ export 'src/cors_options.dart';
typedef bool CorsFilter(String origin);
bool _isOriginAllowed(String origin, allowedOrigin) {
+ allowedOrigin ??= [];
if (allowedOrigin is List) {
return allowedOrigin.any((x) => _isOriginAllowed(origin, x));
} else if (allowedOrigin is String) {
return origin == allowedOrigin;
} else if (allowedOrigin is RegExp) {
- return allowedOrigin.hasMatch(origin);
- } else if (allowedOrigin is CorsFilter) {
+ return origin != null && allowedOrigin.hasMatch(origin);
+ } else if (origin != null && allowedOrigin is CorsFilter) {
return allowedOrigin(origin);
} else {
return allowedOrigin != false;
@@ -29,7 +30,7 @@ RequestMiddleware cors([CorsOptions options]) {
return (RequestContext req, ResponseContext res) async {
// Access-Control-Allow-Credentials
if (opts.credentials == true) {
- res.heades['Access-Control-Allow-Credentials'] = 'true';
+ res.headers['Access-Control-Allow-Credentials'] = 'true';
}
// Access-Control-Allow-Headers
diff --git a/pubspec.yaml b/pubspec.yaml
index 532102c7..b410aa0b 100644
--- a/pubspec.yaml
+++ b/pubspec.yaml
@@ -4,7 +4,7 @@ environment:
sdk: ">=1.19.0"
homepage: "https://github.com/angel-dart/cors.git"
name: "angel_cors"
-version: 1.0.0+1
+version: 1.0.0+2
dependencies:
angel_framework: "^1.0.0-dev"
dev_dependencies:
diff --git a/test/basic_test.dart b/test/basic_test.dart
index 1604dbff..66c11978 100644
--- a/test/basic_test.dart
+++ b/test/basic_test.dart
@@ -12,7 +12,7 @@ main() {
setUp(() async {
app = new Angel()
- ..before.add(cors())
+ ..before.add(cors(new CorsOptions()))
..post('/', (req, res) async {
res.write('hello world');
return false;
@@ -42,9 +42,8 @@ main() {
});
test('mirror headers', () async {
- final response = await client.post(url, headers: {
- 'access-control-request-headers': 'foo'
- });
+ final response = await client
+ .post(url, headers: {'access-control-request-headers': 'foo'});
expect(response.statusCode, equals(200));
print('Response: ${response.body}');
print('Headers: ${response.headers}');