Skip to content

Instantly share code, notes, and snippets.

Created July 20, 2020 18:35
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
Simple HTTP2 echo headers
package main
import (
var keyPath string
var crtPath string
func init() {
flag.StringVar(&keyPath, "tls-key", "server.key", "Path of TLS private key")
flag.StringVar(&crtPath, "tls-crt", "server.crt", "Path of TLS certificate / public key")
func main() {
srv := &http.Server{Addr: ":8000", Handler: http.HandlerFunc(handle)}
log.Printf("Serving on")
// to generate keys: openssl req -newkey rsa:2048 -nodes -keyout server.key -x509 -days 365 -out server.crt
log.Fatal(srv.ListenAndServeTLS(crtPath, keyPath))
func handle(w http.ResponseWriter, r *http.Request) {
delay, err := time.ParseDuration(r.URL.Query().Get("delay"))
if err == nil {
fmt.Fprintf(w, "%s %s %s\n", r.Method, r.RequestURI, r.Proto)
log.Printf("%s %s %s - (remoteAddr: %s, delay: %v)\n", r.Method, r.RequestURI, r.Proto, r.RemoteAddr, delay)
for name, headers := range r.Header {
for _, h := range headers {
fmt.Fprintf(w, "%v: %v\n", name, h)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment