h2c

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jul 20, 2018 License: MPL-2.0 Imports: 14 Imported by: 4

README

h2c

Golang HTTP/2 cleartext (h2c) Handler / Router / Mux

The h2c protocol is the non-TLS secured version of HTTP/2 which is not available from net/http.

Code is a copy of Traefik's h2c server, but adapted for standalone usage as an http.Handler.

Traefik can be found here: github.com/containous/traefik

Please do not use this library unless you know what you are doing, and you have an appropriate use case such as a secure load balancer that terminates SSL before sending h2c traffic to servers within a private subnet.

Example usage:

package main

import (
	"fmt"
	"net/http"

	"github.com/veqryn/h2c"
	"golang.org/x/net/http2"
)

func main() {

	router := http.NewServeMux()

	router.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
		fmt.Fprint(w, "Hello World")
	})

	h2cWrapper := &h2c.HandlerH2C{
		Handler:  router,
		H2Server: &http2.Server{},
	}

	srv := http.Server{
		Addr:    ":8080",
		Handler: h2cWrapper,
	}

	srv.ListenAndServe()
}

Documentation

Overview

Package h2c implements the h2c part of HTTP/2.

The h2c protocol is the non-TLS secured version of HTTP/2 which is not available from net/http.

Code is a copy of Traefik's h2c server, but adapted for standalone usage as an http.Handler.

Traefik can be found here: github.com/containous/traefik

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type HandlerH2C

type HandlerH2C struct {
	Handler  http.Handler
	H2Server *http2.Server
}

HandlerH2C implements http.Handler and enables h2c. Users who want h2c just need to provide a http.Handler to wrap, and an http2.Server.

Example:

router := http.NewServeMux()

router.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
	fmt.Fprint(w, "Hello World")
})

h2cWrapper := &h2c.HandlerH2C{
	Handler:  router,
	H2Server: &http2.Server{},
}

srv := http.Server{
	Addr:    ":8080",
	Handler: h2cWrapper,
}

srv.ListenAndServe()

func (*HandlerH2C) ServeHTTP

func (h *HandlerH2C) ServeHTTP(w http.ResponseWriter, req *http.Request)

ServeHTTP will serve with an HTTP/2 connection if possible using the `H2Server`. The request will be handled by the wrapped `Handler` in any case.

Jump to

Keyboard shortcuts

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