]> Sergey Matveev's repositories - tofuproxy.git/blobdiff - rounds/transcodeWebP.go
I stopped using Xombrero
[tofuproxy.git] / rounds / transcodeWebP.go
index a3682abe809e80970d6afdd792efcb94506c0d48..7c4995d46c962dd11bbb1a6ef4c508adcf0e28f2 100644 (file)
@@ -1,7 +1,7 @@
 /*
 tofuproxy -- flexible HTTP/HTTPS proxy, TLS terminator, X.509 TOFU
              manager, WARC/geminispace browser
-Copyright (C) 2021 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
@@ -21,32 +21,26 @@ package rounds
 import (
        "fmt"
        "io"
-       "io/ioutil"
        "log"
        "net/http"
        "os"
        "os/exec"
-       "strings"
 
        "go.stargrave.org/tofuproxy/fifos"
 )
 
 const CmdDWebP = "dwebp"
 
-func isXombrero(req *http.Request) bool {
-       return strings.Contains(req.Header.Get("User-Agent"), "AppleWebKit/538.15")
-}
-
 func RoundTranscodeWebP(
        host string,
        resp *http.Response,
        w http.ResponseWriter,
        req *http.Request,
 ) (bool, error) {
-       if resp.Header.Get("Content-Type") != "image/webp" || isXombrero(req) {
+       if resp.Header.Get("Content-Type") != "image/webp" {
                return true, nil
        }
-       tmpFd, err := ioutil.TempFile("", "tofuproxy.*.webp")
+       tmpFd, err := os.CreateTemp("", "tofuproxy.*.webp")
        if err != nil {
                log.Fatalln(err)
        }
@@ -66,6 +60,8 @@ func RoundTranscodeWebP(
        w.Header().Add("Content-Type", "image/png")
        w.WriteHeader(http.StatusOK)
        w.Write(data)
-       fifos.LogVarious <- fmt.Sprintf("%s %s\tWebP transcoded to PNG", req.Method, req.URL)
+       fifos.LogVarious <- fmt.Sprintf(
+               "%s %s\tWebP transcoded to PNG", req.Method, req.URL,
+       )
        return false, nil
 }