"net/http"
"os"
"os/exec"
+ "path/filepath"
"strings"
"time"
caCert *x509.Certificate
caPrv crypto.PrivateKey
transport = http.Transport{
- ForceAttemptHTTP2: false,
- TLSNextProto: make(map[string]func(string, *tls.Conn) http.RoundTripper),
DialTLSContext: dialTLS,
+ ForceAttemptHTTP2: true,
}
+ sessionCache = tls.NewLRUClientSessionCache(1024)
CmdDWebP = "dwebp"
CmdDJXL = "djxl"
+
+ imageExts = map[string]struct{}{
+ ".apng": {},
+ ".avif": {},
+ ".gif": {},
+ ".heic": {},
+ ".jp2": {},
+ ".jpeg": {},
+ ".jpg": {},
+ ".jxl": {},
+ ".mng": {},
+ ".png": {},
+ ".svg": {},
+ ".tif": {},
+ ".tiff": {},
+ ".webp": {},
+ }
)
func dialTLS(ctx context.Context, network, addr string) (net.Conn, error) {
) error {
return verifyCert(host, nil, rawCerts, verifiedChains)
},
+ ClientSessionCache: sessionCache,
+ NextProtos: []string{"h2", "http/1.1"},
}
conn, dialErr := tls.Dial(network, addr, &cfg)
if dialErr != nil {
}
}
connState := conn.ConnectionState()
- sinkTLS <- fmt.Sprintf(
- "%s\t%s %s\t%s",
- strings.TrimSuffix(addr, ":443"),
- ucspi.TLSVersion(connState.Version),
- tls.CipherSuiteName(connState.CipherSuite),
- spkiHash(connState.PeerCertificates[0]),
- )
+ if connState.DidResume {
+ sinkTLS <- fmt.Sprintf(
+ "%s\t%s %s\t%s\t%s",
+ strings.TrimSuffix(addr, ":443"),
+ ucspi.TLSVersion(connState.Version),
+ tls.CipherSuiteName(connState.CipherSuite),
+ spkiHash(connState.PeerCertificates[0]),
+ connState.NegotiatedProtocol,
+ )
+ }
return conn, nil
}
}
}
- if strings.HasPrefix(req.URL.Host, "www.reddit.com") {
+ if host == "www.reddit.com" {
req.URL.Host = "old.reddit.com"
http.Redirect(w, req, req.URL.String(), http.StatusMovedPermanently)
return
}
+ if host == "habrastorage.org" && strings.Contains(req.URL.Path, "r/w780q1") {
+ req.URL.Path = strings.Replace(req.URL.Path, "r/w780q1/", "", 1)
+ http.Redirect(w, req, req.URL.String(), http.StatusFound)
+ return
+ }
+
resp, err := transport.RoundTrip(req)
if err != nil {
sinkErr <- fmt.Sprintf("%s\t%s", req.URL.Host, err.Error())
if strings.Contains(req.Header.Get("User-Agent"), "newsboat/") {
goto NoRedir
}
+ if _, ok := imageExts[filepath.Ext(req.URL.Path)]; ok {
+ goto NoRedir
+ }
redirType = "temporary"
default:
goto NoRedir
location := resp.Header.Get("Location")
w.Write([]byte(
fmt.Sprintf(
- `<html>
-<head><title>%d %s: %s redirection</title></head>
-<body>Redirection to <a href="%s">%s</a>
-</body></html>`,
+ `<html><head><title>%d %s: %s redirection</title></head>
+<body>Redirection to <a href="%s">%s</a></body></html>`,
resp.StatusCode, http.StatusText(resp.StatusCode),
redirType, location, location,
)))