From d6d115377496a884dbdebfb3a5ed86ec2cbce18f Mon Sep 17 00:00:00 2001 From: thosakwe Date: Mon, 5 Dec 2016 00:15:28 -0500 Subject: [PATCH] Welcome to Hollywood... --- README.md | 2 +- lib/angel_cors.dart | 10 +++++----- pubspec.yaml | 2 +- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index fd4fe5bb..4d7c650c 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # cors -![1.0.0-dev](https://img.shields.io/badge/version-1.0.0--dev-red.svg) +![1.0.0-dev+1](https://img.shields.io/badge/version-1.0.0--dev+1-red.svg) ![build status](https://travis-ci.org/angel-dart/cors.svg) Angel CORS middleware. diff --git a/lib/angel_cors.dart b/lib/angel_cors.dart index d2fec8a1..26d204e7 100644 --- a/lib/angel_cors.dart +++ b/lib/angel_cors.dart @@ -42,9 +42,9 @@ RequestMiddleware cors([CorsOptions options]) { } // Access-Control-Allow-Headers - if (opts.allowedHeaders.isNotEmpty) { + if (req.method == 'OPTIONS' && opts.allowedHeaders.isNotEmpty) { res.header('Access-Control-Allow-Headers', opts.allowedHeaders.join(',')); - } else { + } else if (req.method == 'OPTIONS') { res.header('Access-Control-Allow-Headers', req.headers.value('Access-Control-Allow-Headers')); } @@ -56,12 +56,12 @@ RequestMiddleware cors([CorsOptions options]) { } // Access-Control-Allow-Methods - if (opts.methods.isNotEmpty) { + if (req.method == 'OPTIONS' && opts.methods.isNotEmpty) { res.header('Access-Control-Allow-Methods', opts.methods.join(',')); } // Access-Control-Max-Age - if (opts.maxAge != null) { + if (req.method == 'OPTIONS' && opts.maxAge != null) { res.header('Access-Control-Max-Age', opts.maxAge.toString()); } @@ -84,6 +84,6 @@ RequestMiddleware cors([CorsOptions options]) { } } - return true; + return req.method != 'OPTIONS' || opts.preflightContinue; }; } diff --git a/pubspec.yaml b/pubspec.yaml index a2bddae2..b92269d1 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-dev" +version: "1.0.0-dev+1" dependencies: angel_framework: "^1.0.0-dev.28" dev_dependencies: