Skip to content

Instantly share code, notes, and snippets.

@thinktwice13
Last active November 8, 2023 11:42
Show Gist options
  • Save thinktwice13/d619166a0c4aa700e506c3725cfd25ad to your computer and use it in GitHub Desktop.
Save thinktwice13/d619166a0c4aa700e506c3725cfd25ad to your computer and use it in GitHub Desktop.
Go with http2-prior-knowledge
package main
import (
"golang.org/x/net/http2"
"net"
"net/http"
)
func main() {
// curl -v --http2-prior-knowledge http://localhost:8080
listener, err := net.Listen("tcp", "0.0.0.0:8080")
if err != nil {
panic(err)
}
h2s := &http2.Server{}
for {
conn, err := listener.Accept()
if err != nil {
panic(err)
}
h2s.ServeConn(conn, &http2.ServeConnOpts{
Handler: http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
_, _ = w.Write([]byte("Hello World"))
}),
})
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment