+ };
+
+ my $app = $self->StaticWrap($mason);
+ for my $plugin (RT->Config->Get("Plugins")) {
+ my $wrap = $plugin->can("PSGIWrap")
+ or next;
+ $app = $wrap->($plugin, $app);
+ }
+ return $app;
+}
+
+sub StaticWrap {
+ my $self = shift;
+ my $app = shift;
+ my $builder = Plack::Builder->new;
+
+ my $headers = RT::Interface::Web::GetStaticHeaders(Time => 'forever');
+
+ for my $static ( RT->Config->Get('StaticRoots') ) {
+ if ( ref $static && ref $static eq 'HASH' ) {
+ $builder->add_middleware(
+ '+RT::Interface::Web::Middleware::StaticHeaders',
+ path => $static->{'path'},
+ headers => $headers,
+ );
+ $builder->add_middleware(
+ 'Plack::Middleware::Static',
+ pass_through => 1,
+ %$static
+ );
+ }
+ else {
+ $RT::Logger->error(
+ "Invalid config StaticRoots: item can only be a hashref" );
+ }
+ }
+
+ my $path = sub { s!^/static/!! };
+ $builder->add_middleware(
+ '+RT::Interface::Web::Middleware::StaticHeaders',
+ path => $path,
+ headers => $headers,
+ );
+ for my $root (RT::Interface::Web->StaticRoots) {
+ $builder->add_middleware(
+ 'Plack::Middleware::Static',
+ path => $path,
+ root => $root,
+ pass_through => 1,
+ );
+ }
+ return $builder->to_app($app);
+}