]> Sergey Matveev's repositories - tofuproxy.git/blobdiff - tls.go
More Fprintf usage
[tofuproxy.git] / tls.go
diff --git a/tls.go b/tls.go
index 05d21db2fc6dffc8ea117e3808a4ba0a10f5b152..ef43964c83eb4b475c90b3602e1b775ab00142a4 100644 (file)
--- a/tls.go
+++ b/tls.go
@@ -1,7 +1,7 @@
 /*
 tofuproxy -- flexible HTTP/HTTPS proxy, TLS terminator, X.509 TOFU
              manager, WARC/geminispace browser
-Copyright (C) 2021-2022 Sergey Matveev <stargrave@stargrave.org>
+Copyright (C) 2021-2023 Sergey Matveev <stargrave@stargrave.org>
 
 This program is free software: you can redistribute it and/or modify
 it under the terms of the GNU General Public License as published by
@@ -25,8 +25,9 @@ import (
        "fmt"
        "log"
        "net/http"
-       "strings"
        "time"
+
+       ttls "go.stargrave.org/tofuproxy/tls"
 )
 
 var (
@@ -52,12 +53,11 @@ func (h *Handler) ServeHTTP(w http.ResponseWriter, req *http.Request) {
                log.Fatalln(err)
        }
        defer conn.Close()
-       conn.Write([]byte(fmt.Sprintf(
-               "%s %d %s\r\n\r\n",
-               req.Proto,
-               http.StatusOK, http.StatusText(http.StatusOK),
-       )))
-       host := strings.Split(req.Host, ":")[0]
+       fmt.Fprintf(
+               conn, "%s %d %s\r\n\r\n",
+               req.Proto, http.StatusOK, http.StatusText(http.StatusOK),
+       )
+       host, _, _ := ttls.SplitHostPort(req.Host)
        hostCertsM.Lock()
        keypair, ok := hostCerts[host]
        if !ok || !keypair.cert.NotAfter.After(time.Now().Add(time.Hour)) {