Permalink
Browse files

Disable HTTP/2, enable session tickets

Cloudflare sometimes disconnects mid-response.
  • Loading branch information...
timothy003 committed Aug 6, 2018
1 parent cc39137 commit 620caf9961286f83e1ada24a1c8a1105958c0957
Showing with 12 additions and 0 deletions.
  1. +12 −0 main.go
12 main.go
@@ -3,6 +3,7 @@ package main
import (
"bytes"
"context"
"crypto/tls"
"html/template"
"io"
"io/ioutil"
@@ -13,6 +14,7 @@ import (
"os/signal"
"strings"
"syscall"
"time"
)

var (
@@ -26,6 +28,16 @@ func main() {
log.Fatal("$PORT must be set")
}

// disable HTTP/2 client
tr := http.DefaultTransport.(*http.Transport)
tr.TLSClientConfig = &tls.Config{
ClientSessionCache: tls.NewLRUClientSessionCache(0),
}
tr.MaxIdleConns = 0
tr.MaxIdleConnsPerHost = int(^uint(0) >> 1) // unlimited
tr.IdleConnTimeout = 300 * time.Second
tr.TLSNextProto = map[string]func(string, *tls.Conn) http.RoundTripper{}

var err error
if links, err = ioutil.ReadFile("links.html"); err != nil {
log.Fatal("failed to read links.html: ", err)

0 comments on commit 620caf9

Please sign in to comment.