Documentation
¶
Overview ¶
Package h2c implements HTTP/2 h2c.
HTTP/2 h2c server implementation would not available in golang standard library because of the policy. This package provides h2c handy implementation.
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ParseSettings ¶
Converts byte slice of SETTINGS frame payload into http2.Setting slice.
Types ¶
type InitRequest ¶
type InitRequest struct { Settings []http2.Setting // HTTP2-Settings parameters HeaderBlock []byte // http2 header block hpack-ed from HTTP/1.1 headers }
func InitH2c ¶
func InitH2c(req *http.Request) *InitRequest
Prepares an http/2 request binaries from http.Request. Returns nil if upgrade failed.
type Server ¶
type Server struct { // Actual content handler http.Handler // Disable RFC 7540 3.4 behavior DisableDirect bool }
Example (ServeHTTP) ¶
Server implements http.Handler interface. Server wraps the entire http site under HTTP/2 h2c by default. if Client wants to upgrade the connection, then connection will be automatically switch to HTTP/2 protocol. If you'd like to control the path, you can manually set the inner http.Handler.
http.HandleFunc("/", func(w http.ResposneWriter, r *http.Request) { fmt.Fprintf(w, "hello") }) log.Fatal(http.ListenAndServe(":8080", &h2c.Server{}))
Output:
Click to show internal directories.
Click to hide internal directories.