Skip to content
This repository was archived by the owner on Jan 24, 2019. It is now read-only.

Commit f511cac

Browse files
authored
Merge pull request #365 from travisofthenorth/fix/default-http-address
Fix url parse error
2 parents 120a47a + f983933 commit f511cac

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

http.go

+11-7
Original file line numberDiff line numberDiff line change
@@ -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

2625
func (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 {

0 commit comments

Comments
 (0)