git.iko.soy/typeable/oauth2-proxy
on master help sign in
Parse http address without url
commitf983933d88ee7979bb6176a94365d037272e3360 authorTravis Hunter <travis.c.hunter@gmail.com> dateSat 1 Apr 2017, 15:10 (10 years ago) parentaf7be2d
1 file changed+11−7
http.go+11−7
http.go+11−7
@@ -5,7 +5,6 @@ import (
55 "log"
66 "net"
77 "net/http"
8− "net/url"
98 "strings"
109 "time"
1110)
@@ -24,19 +23,24 @@ func (s *Server) ListenAndServe() {
2423}
2524
2625func (s *Server) ServeHTTP() {
27− u, err := url.Parse(s.Opts.HttpAddress)
28− if err != nil {
29− log.Fatalf("FATAL: could not parse %#v: %v", s.Opts.HttpAddress, err)
26+ httpAddress := s.Opts.HttpAddress
27+ scheme := ""
28+
29+ i := strings.Index(httpAddress, "://")
30+ if i > -1 {
31+ scheme = httpAddress[0:i]
3032 }
3133
3234 var networkType string
33− switch u.Scheme {
35+ switch scheme {
3436 case "", "http":
3537 networkType = "tcp"
3638 default:
37− networkType = u.Scheme
39+ networkType = scheme
3840 }
39− listenAddr := strings.TrimPrefix(u.String(), u.Scheme+"://")
41+
42+ slice := strings.SplitN(httpAddress, "//", 2)
43+ listenAddr := slice[len(slice)-1]
4044
4145 listener, err := net.Listen(networkType, listenAddr)
4246 if err != nil {