mirror of https://github.com/golang/go.git
net/http: lock the read-only mutex in shouldRedirect
Since that method uses 'mux.m', we need to lock the mutex to avoid data races.
This commit is contained in:
parent
f6c6781302
commit
163a7d4942
|
|
@ -581,6 +581,16 @@ func TestServeWithSlashRedirectForHostPatterns(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestShouldRedirectConcurrency(t *testing.T) {
|
||||
setParallel(t)
|
||||
defer afterTest(t)
|
||||
|
||||
mux := NewServeMux()
|
||||
ts := httptest.NewServer(mux)
|
||||
defer ts.Close()
|
||||
mux.HandleFunc("/", func(w ResponseWriter, r *Request) {})
|
||||
}
|
||||
|
||||
func BenchmarkServeMux(b *testing.B) {
|
||||
|
||||
type test struct {
|
||||
|
|
|
|||
|
|
@ -2223,6 +2223,9 @@ func (mux *ServeMux) redirectToPathSlash(host, path string, u *url.URL) (*url.UR
|
|||
// path+"/". This should happen if a handler is registered for path+"/" but
|
||||
// not path -- see comments at ServeMux.
|
||||
func (mux *ServeMux) shouldRedirect(host, path string) bool {
|
||||
mux.mu.RLock()
|
||||
defer mux.mu.RUnlock()
|
||||
|
||||
p := []string{path, host + path}
|
||||
|
||||
for _, c := range p {
|
||||
|
|
|
|||
Loading…
Reference in New Issue