Add cache-control headers to sendJSONresponse (#2234)

This commit is contained in:
Maxime Besson 2020-06-10 22:03:53 +02:00
parent 768a7b0ecb
commit 5df1850847

View File

@ -1120,6 +1120,18 @@ sub sendJSONresponse {
my ( $self, $req, $j, %args ) = @_;
my $res = Lemonldap::NG::Common::PSGI::sendJSONresponse(@_);
# Handle caching
if ( $args{ttl} and $args{ttl} =~ /^\d+$/ ) {
push @{ $res->[1] },
'Cache-Control' => 'public, max-age=' . $args{ttl};
}
else {
push @{ $res->[1] },
'Cache-Control' => 'no-cache, no-store, must-revalidate',
'Pragma' => 'no-cache',
'Expires' => '0';
}
# If this is a cross-domain request from the portal itself
# (Ajax SSL to a different VHost)
# we allow CORS