Closed geekodour closed 5 years ago
Your issue title says "in httptest", but you're proposing modifying net/http, right? Not httptest?
Can't you just write two small tests rather than one big test?
Or use subtests? Or re-create the ServeMux?
Or use an http.Handler implementation that does the switcheroo muxing itself?
@bradfitz I managed to do this with recreating the ServeMux for each test.
Your issue title says "in httptest", but you're proposing modifying net/http, right? Not httptest?
I thought, for net/http's mux
, it is desirable that It does panic on duplicate pattern.
So, a separate mux
implementation in net/http/httptest
which allows changing of handlers for the same pattern.
Otherwise,
We can add another method such as mux.HandleNoPanic
to net/http
which does not panic on duplicate pattern.
But I don't know if it was necessary, I cannot think of any other usecase other than the original issue I listed above for the test which I was able to solve by recreating the ServeMux
Okay, let's close this then. If other needs emerge later we can discuss then.
Currently the
mux.Handle
implementation innet/http
panics if a handler already exists for pattern.For a test I was writing, It would be nice if I could change the handler for a
pattern
.If this is a feature that can be added, I'll be happy to send a PR.
https://godoc.org/net/http#ServeMux.Handle