1
0
mirror of https://github.com/oauth2-proxy/oauth2-proxy.git synced 2024-11-24 08:52:25 +02:00

Merge pull request #365 from travisofthenorth/fix/default-http-address

Fix url parse error
This commit is contained in:
Jehiah Czebotar 2017-04-20 14:57:39 -04:00 committed by GitHub
commit f511cac6a6

18
http.go
View File

@ -5,7 +5,6 @@ import (
"log" "log"
"net" "net"
"net/http" "net/http"
"net/url"
"strings" "strings"
"time" "time"
) )
@ -24,19 +23,24 @@ func (s *Server) ListenAndServe() {
} }
func (s *Server) ServeHTTP() { func (s *Server) ServeHTTP() {
u, err := url.Parse(s.Opts.HttpAddress) httpAddress := s.Opts.HttpAddress
if err != nil { scheme := ""
log.Fatalf("FATAL: could not parse %#v: %v", s.Opts.HttpAddress, err)
i := strings.Index(httpAddress, "://")
if i > -1 {
scheme = httpAddress[0:i]
} }
var networkType string var networkType string
switch u.Scheme { switch scheme {
case "", "http": case "", "http":
networkType = "tcp" networkType = "tcp"
default: 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) listener, err := net.Listen(networkType, listenAddr)
if err != nil { if err != nil {