Since the internet failed me, and the only working example of a H2C client I
can find was in the actual go code test suite, I’m going to lay out what I
discovered about H2C support in golang here.
First is that the standard golang code supports HTTP2 but does not
directly support H2C. H2C support only exists in the golang.org/x/net/http2/h2c
package. You can make your HTTP server H2C capable by wrapping your handler or
mux with h2c.NewHandler() like so.
The above code allows the server to support
H2C upgrade and
H2C prior knowledge along with
standard HTTP/2 and HTTP/1.1 that golang natively supports.
If you don’t care about supporting HTTP/1.1 then you can run this code which only
supports H2C prior knowledge.
Once you have a running server you can test your server by installing curl-openssl.
You can now use curl to test your H2C enabled server like so.
Connect via HTTP1.1 then upgrade to HTTP/2 (H2C) §
Now, Remember when I said that the golang standard library does not support H2C?
While that is technically correct there is a workaround to get the golang
standard http2 client to connect to an H2C enabled server.
To do so you have to override DialTLS and set the super secret AllowHTTP flag.
Although this all looks a little wonky it actually works really well and
performs nicely in production environments.