File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -72,6 +72,16 @@ JSON_ERROR_LOG: 0
7272# /pg_files:
7373# Access-Control-Allow-Origin: '*'
7474
75+ # The extra_ssl_headers option is much like the extra_headers option above,
76+ # except that these headers are only added to responses to secure SSL requests.
77+ # The example below adds the Strict-Transport-Security header to responses to
78+ # all SSL requests. Note that like the extra_headers option above, headers can
79+ # be added to only specific paths as well (but only if the request is secure).
80+
81+ # extra_ssl_headers:
82+ # '.*':
83+ # Strict-Transport-Security: 'max-age=31536000; includeSubDomains; preload'
84+
7585# The user and group to run the server as. These are only used when the
7686# webwork2 app is in production mode and run as the root user. This means that
7787# these settings are not used when proxying via another web server like apache2
Original file line number Diff line number Diff line change @@ -100,13 +100,24 @@ sub startup ($app) {
100100 );
101101
102102 # Add a hook to add extra headers if set in the config file.
103- if (ref $config -> {extra_headers } eq ' HASH' ) {
103+ if (ref $config -> {extra_headers } eq ' HASH' || ref $config -> {extra_ssl_headers } eq ' HASH' ) {
104+ my $extraHeaders = ref $config -> {extra_headers } eq ' HASH' ? $config -> {extra_headers } : {};
105+ my $extraSSLHeaders = ref $config -> {extra_ssl_headers } eq ' HASH' ? $config -> {extra_ssl_headers } : {};
104106 $app -> hook(
105107 before_dispatch => sub ($c ) {
106- for my $path (keys %{ $config -> { extra_headers } } ) {
108+ for my $path (keys %$extraHeaders ) {
107109 if ($c -> req-> url-> path =~ / ^$path / ) {
108- for (keys %{ $config -> {extra_headers }{$path } }) {
109- $c -> res-> headers-> header($_ => $config -> {extra_headers }{$path }{$_ });
110+ for (keys %{ $extraHeaders -> {$path } }) {
111+ $c -> res-> headers-> header($_ => $extraHeaders -> {$path }{$_ });
112+ }
113+ }
114+ }
115+ if ($c -> req-> is_secure) {
116+ for my $path (keys %$extraSSLHeaders ) {
117+ if ($c -> req-> url-> path =~ / ^$path / ) {
118+ for (keys %{ $extraSSLHeaders -> {$path } }) {
119+ $c -> res-> headers-> header($_ => $extraSSLHeaders -> {$path }{$_ });
120+ }
110121 }
111122 }
112123 }
You can’t perform that action at this time.
0 commit comments