From f983933d88ee7979bb6176a94365d037272e3360 Mon Sep 17 00:00:00 2001 From: Travis Hunter Date: Sat, 1 Apr 2017 15:10:33 -0400 Subject: [PATCH] Parse http address without url --- http.go | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/http.go b/http.go index 3b3d13867..aa764c842 100644 --- a/http.go +++ b/http.go @@ -5,7 +5,6 @@ import ( "log" "net" "net/http" - "net/url" "strings" "time" ) @@ -24,19 +23,24 @@ func (s *Server) ListenAndServe() { } func (s *Server) ServeHTTP() { - u, err := url.Parse(s.Opts.HttpAddress) - if err != nil { - log.Fatalf("FATAL: could not parse %#v: %v", s.Opts.HttpAddress, err) + httpAddress := s.Opts.HttpAddress + scheme := "" + + i := strings.Index(httpAddress, "://") + if i > -1 { + scheme = httpAddress[0:i] } var networkType string - switch u.Scheme { + switch scheme { case "", "http": networkType = "tcp" default: - networkType = u.Scheme + networkType = scheme } - listenAddr := strings.TrimPrefix(u.String(), u.Scheme+"://") + + slice := strings.SplitN(httpAddress, "//", 2) + listenAddr := slice[len(slice)-1] listener, err := net.Listen(networkType, listenAddr) if err != nil {