Support X-Forwarded-Host name for proxy

Change-Id: I50b11be093cd63217e685f6dccecad9fcdbc0898
diff --git a/lib/Kalamar.pm b/lib/Kalamar.pm
index cb8d6ab..3a60f5c 100644
--- a/lib/Kalamar.pm
+++ b/lib/Kalamar.pm
@@ -105,6 +105,24 @@
       });
   };
 
+  $conf->{proxy_host} //= 1;
+
+  # Take proxy host
+  if ($conf->{proxy_host}) {
+    $self->hook(
+      before_dispatch => sub {
+        my $c = shift;
+        if (my $host = $c->req->headers->header('X-Forwarded-Host')) {
+          foreach ($c->req->url->base) {
+            $_->host($host);
+            $_->scheme(undef);
+            $_->port(undef);
+          };
+        };
+      }
+    );
+  };
+
   # API is not yet set - define
   $conf->{api_path} //= $ENV{KALAMAR_API};
   $conf->{api_version} //= $API_VERSION;