Emit 'after_render' hook in proxy to make requests accessible for post processing
Change-Id: Ica93aad2b46d34583751883159b58f40a34c0517
diff --git a/Changes b/Changes
index ee8858a..ad83167 100755
--- a/Changes
+++ b/Changes
@@ -1,9 +1,12 @@
-0.36 2019-07-25
+0.36 2019-08-07
- Rename all cookies to be independent
for different instance (#94).
- Enable https only via
configuration option 'https_only'.
- Make VC replaceable via KorAP.vc.fromJson().
+ - Emit 'after_render' in proxy responses
+ to make it accessible to post processing
+ (such as the Piwik plugin).
WARNING: This requires relogin for all users!
diff --git a/lib/Kalamar/Controller/Proxy.pm b/lib/Kalamar/Controller/Proxy.pm
index 4bb4116..aff9d8a 100644
--- a/lib/Kalamar/Controller/Proxy.pm
+++ b/lib/Kalamar/Controller/Proxy.pm
@@ -49,6 +49,8 @@
# another proxy, e.g. Apache, manages multiple
# connections
$headers->connection('close');
+
+ $c->app->plugins->emit_hook(after_render => $c);
}
);
};
diff --git a/t/proxy.t b/t/proxy.t
index f30e049..2e2f922 100644
--- a/t/proxy.t
+++ b/t/proxy.t
@@ -33,22 +33,44 @@
# Globally set server
$t->app->ua->server->app($t->app);
+my $rendered = 0;
+$t->app->hook(
+ after_render => sub {
+ $rendered++;
+ }
+);
+
+$t->get_ok('/doc')
+ ->status_is(200)
+ ->text_like('title', qr!KorAP!)
+ ;
+
+is($rendered, 1);
+
$t->get_ok('/realapi/v1.0')
->status_is(200)
->content_is('Fake server available')
;
+is($rendered, 1);
+
$t->get_ok('/api/v1.0/')
->status_is(200)
->content_is('Fake server available')
;
+# Proxy renders
+is($rendered, 2);
+
$t->get_ok('/api/v1.0/search?ql=cosmas3')
->status_is(400)
->json_is('/errors/0/0','307')
->header_is('connection', 'close')
;
+# Proxy renders
+is($rendered, 3);
+
$t->post_ok('/api/v1.0/oauth2/token' => {} => form => {
username => 'test',
password => 'pass'