Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

httplibp2p: cannot set a custom ServeMux #2546

Closed
aschmahmann opened this issue Aug 31, 2023 · 0 comments · Fixed by #2548
Closed

httplibp2p: cannot set a custom ServeMux #2546

aschmahmann opened this issue Aug 31, 2023 · 0 comments · Fixed by #2548

Comments

@aschmahmann
Copy link
Collaborator

The libp2phttp host's ServeMux is supposed to be modifiable by the user

// ServeMux is the http.ServeMux used by the server to serve requests. If
// nil, a new serve mux will be created. Users may manually add handlers to
// this mux instead of using `SetHTTPHandler`, but if they do, they should
// also update the WellKnownHandler's protocol mapping.
ServeMux *http.ServeMux

Unfortunately, without some hackery this is difficult to do because creating a custom ServeMux will result in that ServeMux getting clobbered by

func (h *Host) serveMuxInit() {
h.initializeServeMux.Do(func() {
h.ServeMux = http.NewServeMux()
})
}
that's called in functions like
func (h *Host) Serve() error {
.

Seems like this is most easily fixable by adding a guard to check if the *ServeMux is nil before initializing it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant