Close connections in proxy as a workaround for problematic connection handling in embedding proxies

Change-Id: I489dd64d5f965645c596163935d6fb6f94f4bbfe
diff --git a/lib/Kalamar/Controller/Proxy.pm b/lib/Kalamar/Controller/Proxy.pm
index ed9acef..4bb4116 100644
--- a/lib/Kalamar/Controller/Proxy.pm
+++ b/lib/Kalamar/Controller/Proxy.pm
@@ -24,7 +24,6 @@
 
   # Get parameters of the request
   my $params = $req->query_params->clone;
-  my $api_url;
 
   # Get API request for proxying
   my $url = Mojo::URL->new($c->korap->api($apiv))->path($path)->query($params);
@@ -40,14 +39,18 @@
     before_korap_request => ($c, $tx)
   );
 
-  # return $c->render(text => 'okay ' . $url);
-
   $c->proxy->start_p($tx)->wait;
-  # $tx->res->content->once(
-  #   body => sub {
-  #     $c->res->headers->header('X-Proxy' => 'Kalamar');
-  #   }
-  # );
+  $tx->res->content->once(
+    body => sub {
+      my $headers = $c->res->headers;
+      $headers->header('X-Proxy' => 'Kalamar');
+
+      # Workaround for a proxy problem when
+      # another proxy, e.g. Apache, manages multiple
+      # connections
+      $headers->connection('close');
+    }
+  );
 };
 
 1;
diff --git a/t/proxy.t b/t/proxy.t
index f754f11..84f029e 100644
--- a/t/proxy.t
+++ b/t/proxy.t
@@ -51,6 +51,7 @@
 $t->get_ok('/api/v1.0/search?ql=cosmas3')
   ->status_is(400)
   ->json_is('/errors/0/0','307')
+  ->header_is('connection', 'close')
   ;
 
 $t->post_ok('/api/v1.0/oauth2/token' => {} => form => {