File Coverage

example/CookieWrapper.pm
Criterion Covered Total %
statement 6 22 27.2
branch n/a
condition n/a
subroutine 2 4 50.0
pod 1 1 100.0
total 9 27 33.3


line stmt bran cond sub pod time code
1             package CookieWrapper;
2 1     1   682 use Mojo::Base 'Mojolicious';
  1         1  
  1         5  
3              
4             # This method will run once at server start
5             sub startup {
6 1     1 1 11471 my $app = shift;
7              
8 1         12 $app->secrets(['some secure secret']);
9              
10             $app->plugin('Mojolicious::Plugin::ReverseProxy',{
11             destination_url => 'http://google.com/',
12             req_processor => sub {
13 0     0     my $ctrl= shift;
14 0           my $req = shift;
15 0           my $opt = shift;
16             # get cookies from session
17 0           $req->headers->remove('cookie');
18 0           my $cookies = $ctrl->session->{cookies};
19 0           $req->cookies(map { { name => $_, value => $cookies->{$_} } } keys %$cookies);
  0            
20             },
21             res_processor => sub {
22 0     0     my $ctrl = shift;
23 0           my $res = shift;
24 0           my $opt = shift;
25            
26             # for fun, remove all the cookies
27 0           my $cookies = $res->cookies;
28 0           my $session = $ctrl->session;
29 0           for my $cookie (@{$res->cookies}){
  0            
30 0           $session->{cookies}{$cookie->name} = $cookie->value;
31             }
32             # as the session will get applied later on
33 0           $res->headers->remove('set-cookie');
34             }
35 1         33 });
36             }
37              
38             1;