-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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 mount a protocol at the root #2545
Comments
Can you elaborate here? I'm not sure if this is a problem, but my understanding of the http work is not great. I'm using this example host and making requests via curl: func Test_ExampleHost_RootPath(t *testing.T) {
// Create the server
server := libp2phttp.Host{
InsecureAllowHTTP: true, // For our example, we'll allow insecure HTTP
ListenAddrs: []ma.Multiaddr{ma.StringCast("/ip4/127.0.0.1/tcp/50221/http")},
}
server.SetHTTPHandlerAtPath("/hello/1", "/", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
fmt.Println(r.URL.Path)
w.Header().Add("Content-Type", "text/plain")
w.Write([]byte("Hello World"))
}))
server.Serve()
} This works fine with curl: This also works with: using In https://cs.opensource.google/go/go/+/refs/tags/go1.21.0:src/net/http/server.go;l=2475-2479 |
They are also not the same if Maybe I'm misunderstanding how the composition is supposed to work here, but my understanding is that the Thanks for your test example, it gives something to write against. Here's a similar example demonstrating an infinite loop issue that comes up with nested Using standard HTTP ServeMux:
Using an httplibp2p host as the root:
|
Thanks! This clarified the issue. There is a bug in the happy case too here. See the PR. |
It seems from the spec PR that it should be possible to mount a protocol at the root (i.e.
/
).However, from what I can tell though this will cause problems in go-libp2p because the
/
will be sliced off the prefixgo-libp2p/p2p/http/libp2phttp.go
Line 371 in 87a8d4e
path != r.URL.Path
will always be the case due to slicing the/
off the front.The text was updated successfully, but these errors were encountered: