From cd1c910a13ed3ce03455fd8ea6cb6aed2d3e3f4e Mon Sep 17 00:00:00 2001 From: thosakwe Date: Wed, 21 Dec 2016 12:43:42 -0500 Subject: [PATCH] :) --- README.md | 2 +- lib/angel_cors.dart | 38 +++++++++++++++----------------------- pubspec.yaml | 4 ++-- 3 files changed, 18 insertions(+), 26 deletions(-) diff --git a/README.md b/README.md index 4d7c650c..26d9e610 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # cors -![1.0.0-dev+1](https://img.shields.io/badge/version-1.0.0--dev+1-red.svg) +![1.0.0-dev+2](https://img.shields.io/badge/version-1.0.0--dev+2-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 26d204e7..a2cc6cbb 100644 --- a/lib/angel_cors.dart +++ b/lib/angel_cors.dart @@ -26,61 +26,53 @@ bool _isOriginAllowed(String origin, allowedOrigin) { RequestMiddleware cors([CorsOptions options]) { 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 { // Access-Control-Allow-Credentials if (opts.credentials == true) { - res.header('Access-Control-Allow-Credentials', 'true'); + res.heades['Access-Control-Allow-Credentials'] = 'true'; } // Access-Control-Allow-Headers if (req.method == 'OPTIONS' && opts.allowedHeaders.isNotEmpty) { - res.header('Access-Control-Allow-Headers', opts.allowedHeaders.join(',')); + res.headers['Access-Control-Allow-Headers'] = + opts.allowedHeaders.join(','); } else if (req.method == 'OPTIONS') { - res.header('Access-Control-Allow-Headers', - req.headers.value('Access-Control-Allow-Headers')); + res.headers['Access-Control-Allow-Headers'] = + req.headers.value('Access-Control-Allow-Headers'); } // Access-Control-Expose-Headers if (opts.exposedHeaders.isNotEmpty) { - res.header( - 'Access-Control-Expose-Headers', opts.exposedHeaders.join(',')); + res.headers['Access-Control-Expose-Headers'] = + opts.exposedHeaders.join(','); } // Access-Control-Allow-Methods if (req.method == 'OPTIONS' && opts.methods.isNotEmpty) { - res.header('Access-Control-Allow-Methods', opts.methods.join(',')); + res.headers['Access-Control-Allow-Methods'] = opts.methods.join(','); } // Access-Control-Max-Age if (req.method == 'OPTIONS' && opts.maxAge != null) { - res.header('Access-Control-Max-Age', opts.maxAge.toString()); + res.headers['Access-Control-Max-Age'] = opts.maxAge.toString(); } // Access-Control-Allow-Origin if (opts.origin == false || opts.origin == '*') { - res.header('Access-Control-Allow-Origin', '*'); + res.headers['Access-Control-Allow-Origin'] = '*'; } else if (opts.origin is String) { res - ..header('Access-Control-Allow-Origin', opts.origin) - ..header('Vary', 'Origin'); + ..headers['Access-Control-Allow-Origin'] = opts.origin + ..headers['Vary'] = 'Origin'; } else { bool isAllowed = _isOriginAllowed(req.headers.value('Origin'), opts.origin); - res.header('Access-Control-Allow-Origin', - isAllowed ? req.headers.value('Origin') : false.toString()); + res.headers['Access-Control-Allow-Origin'] = + isAllowed ? req.headers.value('Origin') : false.toString(); if (isAllowed) { - res.header('Vary', 'Origin'); + res.headers['Vary'] = 'Origin'; } } diff --git a/pubspec.yaml b/pubspec.yaml index b92269d1..286181c6 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -4,9 +4,9 @@ environment: sdk: ">=1.19.0" homepage: "https://github.com/angel-dart/cors.git" name: "angel_cors" -version: "1.0.0-dev+1" +version: "1.0.0-dev+2" dependencies: - angel_framework: "^1.0.0-dev.28" + angel_framework: "^1.0.0-dev" dev_dependencies: http: "^0.11.3+9" test: "^0.12.17"