Skip to content

Instantly share code, notes, and snippets.

@thinktwice13
Last active November 8, 2023 11:42
Show Gist options
  • Select an option

  • Save thinktwice13/d619166a0c4aa700e506c3725cfd25ad to your computer and use it in GitHub Desktop.

Select an option

Save thinktwice13/d619166a0c4aa700e506c3725cfd25ad to your computer and use it in GitHub Desktop.

Revisions

  1. thinktwice13 revised this gist Nov 8, 2023. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion go-http2.go
    Original file line number Diff line number Diff line change
    @@ -20,7 +20,7 @@ func main() {
    panic(err)
    }

    go h2s.ServeConn(conn, &http2.ServeConnOpts{
    h2s.ServeConn(conn, &http2.ServeConnOpts{
    Handler: http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
    _, _ = w.Write([]byte("Hello World"))
    }),
  2. thinktwice13 created this gist Nov 8, 2023.
    29 changes: 29 additions & 0 deletions go-http2.go
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,29 @@
    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)
    }

    go h2s.ServeConn(conn, &http2.ServeConnOpts{
    Handler: http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
    _, _ = w.Write([]byte("Hello World"))
    }),
    })
    }
    }