]> Sergey Matveev's repositories - tofuproxy.git/blobdiff - trip.go
Various refactoring
[tofuproxy.git] / trip.go
diff --git a/trip.go b/trip.go
index 90a5ad3b145c2c742d31112a2f5c2c4421020ad4..73807a7967b418499fd38839559efa470170ddcc 100644 (file)
--- a/trip.go
+++ b/trip.go
@@ -1,5 +1,6 @@
 /*
-tofuproxy -- HTTP proxy with TLS certificates management
+tofuproxy -- flexible HTTP/HTTPS proxy, TLS terminator, X.509 TOFU
+             manager, WARC/geminispace browser
 Copyright (C) 2021 Sergey Matveev <stargrave@stargrave.org>
 
 This program is free software: you can redistribute it and/or modify
@@ -30,6 +31,7 @@ import (
        "go.stargrave.org/tofuproxy/caches"
        "go.stargrave.org/tofuproxy/fifos"
        "go.stargrave.org/tofuproxy/rounds"
+       ttls "go.stargrave.org/tofuproxy/tls"
 )
 
 var (
@@ -41,7 +43,7 @@ var (
                MaxIdleConns:        http.DefaultTransport.(*http.Transport).MaxIdleConns,
                IdleConnTimeout:     http.DefaultTransport.(*http.Transport).IdleConnTimeout * 2,
                TLSHandshakeTimeout: time.Minute,
-               DialTLSContext:      dialTLS,
+               DialTLSContext:      ttls.DialTLS,
                ForceAttemptHTTP2:   true,
        }
        proxyHeaders = map[string]struct{}{
@@ -59,10 +61,13 @@ type Round func(
 ) (bool, error)
 
 func roundTrip(w http.ResponseWriter, req *http.Request) {
+       defer req.Body.Close()
        fifos.LogReq <- fmt.Sprintf("%s %s", req.Method, req.URL)
        host := strings.TrimSuffix(req.URL.Host, ":443")
        for _, round := range []Round{
                rounds.RoundNoHead,
+               rounds.RoundGemini,
+               rounds.RoundWARC,
                rounds.RoundDenySpy,
                rounds.RoundRedditOld,
                rounds.RoundHabrImage,
@@ -78,7 +83,6 @@ func roundTrip(w http.ResponseWriter, req *http.Request) {
        caches.HTTPAuthCacheM.RLock()
        if creds, ok := caches.HTTPAuthCache[req.URL.Host]; ok {
                req.SetBasicAuth(creds[0], creds[1])
-               fifos.LogHTTPAuth <- fmt.Sprintf("%s %s\t%s", req.Method, req.URL, creds[0])
                unauthorized = true
        }
        caches.HTTPAuthCacheM.RUnlock()