Dancer-Plugin-SporeDefinitionControl
view release on metacpan or search on metacpan
Revision history for Dancer-Plugin-SporeDefinitionControl
0.17 2019-04-16, Frédéric Lechauve, Nicolas Oudard
Add Access control header to all requests
0.17 2019-04-05, Frédéric Lechauve, Nicolas Oudard
update the way origin is manage + access-control-allow-credentials on all requests (Frederic Lechauve)
0.16 2019-01-28, Nicolas Oudard
_load_path_validation must be done if path_validation does not exist (Frederic Lechauve)
0.15 2019-01-28, Nicolas Oudard
add the capability to manage method OPTIONS (Frederic Lechauve)
0.14 2016-02-24, Nicolas Oudard
Fix typo in error message when a parameter is wrong (Simon Lenne)
manage form-data in check_spore_definition (Frederic Lechauve)
lib/Dancer/Plugin/SporeDefinitionControl.pm view on Meta::CPAN
{
$error = "parameter `$param' is unknown";
$ko = 1 ;
}
}
next if $ko;
$is_ok = 1;
}
return _returned_error($error,400) unless $is_ok;
#set the access-control-allow-credentials if needed
_set_access_control_header($path_validation->{path}->{$req->{_route_pattern}});
};
};
=head2 get_functions_from_request
return the hash of functions available from method and path.
=cut
lib/Dancer/Plugin/SporeDefinitionControl.pm view on Meta::CPAN
my $req = request;
my %seen = ();
my $build_options_route = plugin_setting->{'build_options_route'};
my @unique_methods = grep { !$seen{$_}++ } @{$methods};
my $origin_allowed;
#check that header contain origin and that url is permit by api
$origin_allowed = $req->header('Origin') if ( defined $req->header('Origin')
&& defined $build_options_route->{'header_allow_allow_origins'}
&& $req->header('Origin') ~~ @{$build_options_route->{'header_allow_allow_origins'}}
);
header 'access-control-allow-credentials' => $build_options_route->{'header_allow_credentials'} || '';
header 'access-control-allow-headers' => $build_options_route->{'header_allow_headers'} || '';
header 'access-control-allow-methods' => join(",",@unique_methods,'OPTIONS');
header 'access-control-allow-origin' => $origin_allowed if defined $origin_allowed;
header 'access-control-max-age' => $build_options_route->{'header_max_age'} || '';
}
=head1 AUTHOR
Nicolas Oudard, C<< <nicolas at oudard.org> >>
t/01-check_spore_definition.t view on Meta::CPAN
use Dancer;
use Dancer::Test;
BEGIN {
set environment => 'test';
set plugins => {
SporeDefinitionControl => {
spore_spec_path => "sample_route.yaml",
build_options_route => {
header_allow_credentials => 'true',
header_allow_headers => 'DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Authorization,Cookie,X-Weborama-UserAuthToken,X-Weborama-Account_Id',
header_allow_allow_origins => [ 'https://testurl1.com', 'https://testurl2.com'],
header_max_age => '1728000',
}
},
};
}
use t::lib::WebService;
( run in 0.379 second using v1.01-cache-2.11-cpan-05444aca049 )