Commit 287543a0 authored by Matt Holt's avatar Matt Holt

Merge pull request #238 from LK4D4/fix_vet

Fix all vet warnings and add vet check to CI
parents 7545755b f2e68043
...@@ -5,4 +5,10 @@ go: ...@@ -5,4 +5,10 @@ go:
- 1.5 - 1.5
- tip - tip
script: go test ./... install:
- go get -d ./...
- go get golang.org/x/tools/cmd/vet
script:
- go vet ./...
- go test ./...
...@@ -117,7 +117,7 @@ md5:$apr1$l42y8rex$pOA2VJ0x/0TwaFeAF9nX61` ...@@ -117,7 +117,7 @@ md5:$apr1$l42y8rex$pOA2VJ0x/0TwaFeAF9nX61`
pwd = fmt.Sprintf("%s%d", pwd, j+1) pwd = fmt.Sprintf("%s%d", pwd, j+1)
} }
if !actualRule.Password(pwd) || actualRule.Password(test.password+"!") { if !actualRule.Password(pwd) || actualRule.Password(test.password+"!") {
t.Errorf("Test %d, rule %d: Expected password '%s', got '%s'", t.Errorf("Test %d, rule %d: Expected password '%v', got '%v'",
i, j, test.password, actualRule.Password) i, j, test.password, actualRule.Password)
} }
......
...@@ -28,5 +28,5 @@ var EmptyNext = middleware.HandlerFunc(func(w http.ResponseWriter, r *http.Reque ...@@ -28,5 +28,5 @@ var EmptyNext = middleware.HandlerFunc(func(w http.ResponseWriter, r *http.Reque
// SameNext does a pointer comparison between next1 and next2. // SameNext does a pointer comparison between next1 and next2.
func SameNext(next1, next2 middleware.Handler) bool { func SameNext(next1, next2 middleware.Handler) bool {
return fmt.Sprintf("%p", next1) == fmt.Sprintf("%p", next2) return fmt.Sprintf("%v", next1) == fmt.Sprintf("%v", next2)
} }
...@@ -27,8 +27,8 @@ func gzipParse(c *Controller) ([]gzip.Config, error) { ...@@ -27,8 +27,8 @@ func gzipParse(c *Controller) ([]gzip.Config, error) {
for c.Next() { for c.Next() {
config := gzip.Config{} config := gzip.Config{}
pathFilter := gzip.PathFilter{make(gzip.Set)} pathFilter := gzip.PathFilter{IgnoredPaths: make(gzip.Set)}
extFilter := gzip.ExtFilter{make(gzip.Set)} extFilter := gzip.ExtFilter{Exts: make(gzip.Set)}
// No extra args expected // No extra args expected
if len(c.RemainingArgs()) > 0 { if len(c.RemainingArgs()) > 0 {
......
...@@ -42,17 +42,17 @@ func TestRewriteParse(t *testing.T) { ...@@ -42,17 +42,17 @@ func TestRewriteParse(t *testing.T) {
expected []rewrite.Rule expected []rewrite.Rule
}{ }{
{`rewrite /from /to`, false, []rewrite.Rule{ {`rewrite /from /to`, false, []rewrite.Rule{
rewrite.SimpleRule{"/from", "/to"}, rewrite.SimpleRule{From: "/from", To: "/to"},
}}, }},
{`rewrite /from /to {`rewrite /from /to
rewrite a b`, false, []rewrite.Rule{ rewrite a b`, false, []rewrite.Rule{
rewrite.SimpleRule{"/from", "/to"}, rewrite.SimpleRule{From: "/from", To: "/to"},
rewrite.SimpleRule{"a", "b"}, rewrite.SimpleRule{From: "a", To: "b"},
}}, }},
{`rewrite a`, true, []rewrite.Rule{}}, {`rewrite a`, true, []rewrite.Rule{}},
{`rewrite`, true, []rewrite.Rule{}}, {`rewrite`, true, []rewrite.Rule{}},
{`rewrite a b c`, true, []rewrite.Rule{ {`rewrite a b c`, true, []rewrite.Rule{
rewrite.SimpleRule{"a", "b"}, rewrite.SimpleRule{From: "a", To: "b"},
}}, }},
} }
...@@ -98,14 +98,14 @@ func TestRewriteParse(t *testing.T) { ...@@ -98,14 +98,14 @@ func TestRewriteParse(t *testing.T) {
r .* r .*
to /to to /to
}`, false, []rewrite.Rule{ }`, false, []rewrite.Rule{
&rewrite.RegexpRule{"/", "/to", nil, regexp.MustCompile(".*")}, &rewrite.RegexpRule{Base: "/", To: "/to", Regexp: regexp.MustCompile(".*")},
}}, }},
{`rewrite { {`rewrite {
regexp .* regexp .*
to /to to /to
ext / html txt ext / html txt
}`, false, []rewrite.Rule{ }`, false, []rewrite.Rule{
&rewrite.RegexpRule{"/", "/to", []string{"/", "html", "txt"}, regexp.MustCompile(".*")}, &rewrite.RegexpRule{Base: "/", To: "/to", Exts: []string{"/", "html", "txt"}, Regexp: regexp.MustCompile(".*")},
}}, }},
{`rewrite /path { {`rewrite /path {
r rr r rr
...@@ -116,8 +116,8 @@ func TestRewriteParse(t *testing.T) { ...@@ -116,8 +116,8 @@ func TestRewriteParse(t *testing.T) {
to /to to /to
} }
`, false, []rewrite.Rule{ `, false, []rewrite.Rule{
&rewrite.RegexpRule{"/path", "/dest", nil, regexp.MustCompile("rr")}, &rewrite.RegexpRule{Base: "/path", To: "/dest", Regexp: regexp.MustCompile("rr")},
&rewrite.RegexpRule{"/", "/to", nil, regexp.MustCompile("[a-z]+")}, &rewrite.RegexpRule{Base: "/", To: "/to", Regexp: regexp.MustCompile("[a-z]+")},
}}, }},
{`rewrite { {`rewrite {
to /to to /to
......
...@@ -113,6 +113,34 @@ func (s *Server) Serve() error { ...@@ -113,6 +113,34 @@ func (s *Server) Serve() error {
return server.ListenAndServe() return server.ListenAndServe()
} }
// copy from net/http/transport.go
func cloneTLSConfig(cfg *tls.Config) *tls.Config {
if cfg == nil {
return &tls.Config{}
}
return &tls.Config{
Rand: cfg.Rand,
Time: cfg.Time,
Certificates: cfg.Certificates,
NameToCertificate: cfg.NameToCertificate,
GetCertificate: cfg.GetCertificate,
RootCAs: cfg.RootCAs,
NextProtos: cfg.NextProtos,
ServerName: cfg.ServerName,
ClientAuth: cfg.ClientAuth,
ClientCAs: cfg.ClientCAs,
InsecureSkipVerify: cfg.InsecureSkipVerify,
CipherSuites: cfg.CipherSuites,
PreferServerCipherSuites: cfg.PreferServerCipherSuites,
SessionTicketsDisabled: cfg.SessionTicketsDisabled,
SessionTicketKey: cfg.SessionTicketKey,
ClientSessionCache: cfg.ClientSessionCache,
MinVersion: cfg.MinVersion,
MaxVersion: cfg.MaxVersion,
CurvePreferences: cfg.CurvePreferences,
}
}
// ListenAndServeTLSWithSNI serves TLS with Server Name Indication (SNI) support, which allows // ListenAndServeTLSWithSNI serves TLS with Server Name Indication (SNI) support, which allows
// multiple sites (different hostnames) to be served from the same address. This method is // multiple sites (different hostnames) to be served from the same address. This method is
// adapted directly from the std lib's net/http ListenAndServeTLS function, which was // adapted directly from the std lib's net/http ListenAndServeTLS function, which was
...@@ -123,10 +151,7 @@ func ListenAndServeTLSWithSNI(srv *http.Server, tlsConfigs []TLSConfig) error { ...@@ -123,10 +151,7 @@ func ListenAndServeTLSWithSNI(srv *http.Server, tlsConfigs []TLSConfig) error {
addr = ":https" addr = ":https"
} }
config := new(tls.Config) config := cloneTLSConfig(srv.TLSConfig)
if srv.TLSConfig != nil {
*config = *srv.TLSConfig
}
if config.NextProtos == nil { if config.NextProtos == nil {
config.NextProtos = []string{"http/1.1"} config.NextProtos = []string{"http/1.1"}
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment