From 2da67206c8b7a13868ac8543ee77729c0f025454 Mon Sep 17 00:00:00 2001 From: Makis Maropoulos Date: Tue, 7 Jun 2016 20:54:34 +0300 Subject: [PATCH] {{ url }} prepends with the listening address and not the real host --- route.go | 3 +-- server/server.go | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/route.go b/route.go index e5a55e10..fd063e3f 100644 --- a/route.go +++ b/route.go @@ -223,8 +223,7 @@ func (r *Route) ParseURI(args ...interface{}) (uri string) { scheme = "https://" } - host := r.station.server.Host() - + host := r.station.server.VirtualHost() arguments := args[0:] // join arrays as arguments diff --git a/server/server.go b/server/server.go index 8bf2e8c4..6a1966be 100644 --- a/server/server.go +++ b/server/server.go @@ -67,6 +67,21 @@ func (s *Server) Host() (host string) { } } +// VirtualHost returns the s.Config.ListeningAddr, if host provided else returns the Listener's (Host()) +// +// Note: currently this is used only on iris/route.ParseURI. +// +func (s *Server) VirtualHost() (host string) { + // we always have at least the :PORT because of parseAddr, so we just + // check if we have anything before PORT + a := s.Config.ListeningAddr + if len(a[0:strings.IndexByte(a, ':')]) > 0 { + return a + } else { + return s.Host() + } +} + // Hostname returns the hostname part only, if host == 0.0.0.0:8080 it will return the 0.0.0.0 // if server is not listening it returns the config.ListeningAddr's hostname part func (s *Server) Hostname() (hostname string) {