This commit is contained in:
Tobe O 2017-11-18 12:30:39 -05:00
parent a24a75cb6a
commit dffb806dc7
7 changed files with 42 additions and 8 deletions

6
.idea/misc.xml Normal file
View file

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectRootManager">
<output url="file://$PROJECT_DIR$/out" />
</component>
</project>

8
.idea/modules.xml Normal file
View file

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/cors.iml" filepath="$PROJECT_DIR$/cors.iml" />
</modules>
</component>
</project>

6
.idea/vcs.xml Normal file
View file

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="" vcs="Git" />
</component>
</project>

14
cors.iml Normal file
View file

@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="WEB_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<excludeFolder url="file://$MODULE_DIR$/.pub" />
<excludeFolder url="file://$MODULE_DIR$/build" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" name="Dart SDK" level="project" />
<orderEntry type="library" name="Dart Packages" level="project" />
</component>
</module>

View file

@ -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

View file

@ -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:

View file

@ -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}');