Last active
November 8, 2023 11:42
-
-
Save thinktwice13/d619166a0c4aa700e506c3725cfd25ad to your computer and use it in GitHub Desktop.
Go with http2-prior-knowledge
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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