h2c

package module
v0.0.0-...-3511cd6 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 7, 2018 License: BSD-3-Clause Imports: 13 Imported by: 32

README

h2c

(Old) golang HTTP/2 h2c server implementation

Please visit x/net/http2/h2c before using this code.

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

func ParseSettings(b []byte) []http2.Setting

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:

func (Server) ServeHTTP

func (u Server) ServeHTTP(w http.ResponseWriter, r *http.Request)

ServeHTTP implements http.Handler interface for HTTP/2 h2c upgrade.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL