@item And wonderful @url{http://jpegxl.info/, JPEG XL} image format is
not supported by most browsers. Even pretty old
@url{https://developers.google.com/speed/webp, WebP} is not supported
-everywhere.
+everywhere. @url{https://aomediacodec.github.io/av1-avif/, AVIF} would
+be useful too.
@end itemize
@item WebP images, if it is not Xombrero, is transcoded to PNG.
-@item JPEG XL images are transparently transcoded to PNG too.
+@item JPEG XL and AVIF images are transparently transcoded to PNG too.
@item Default Go's checks are applied to all certificates. If they pass,
then certificate chain is saved on the disk. Future connections are
--- /dev/null
+/*
+tofuproxy -- HTTP proxy with TLS certificates management
+Copyright (C) 2021 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
+the Free Software Foundation, version 3 of the License.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program. If not, see <http://www.gnu.org/licenses/>.
+*/
+
+package rounds
+
+import (
+ "net/http"
+)
+
+func RoundTranscodeAVIF(
+ host string,
+ resp *http.Response,
+ w http.ResponseWriter,
+ req *http.Request,
+) (bool, error) {
+ return transcodeCmd2Png("image/avif", "avif", "avifdec", resp, w, req)
+}
"go.stargrave.org/tofuproxy/fifos"
)
-const CmdDJXL = "djxl"
-
-func RoundTranscodeJXL(
- host string,
+func transcodeCmd2Png(
+ contentType, ext, cmdName string,
resp *http.Response,
w http.ResponseWriter,
req *http.Request,
) (bool, error) {
- if resp.Header.Get("Content-Type") != "image/jxl" {
+ if resp.Header.Get("Content-Type") != contentType {
return true, nil
}
- tmpFd, err := ioutil.TempFile("", "tofuproxy.*.jxl")
+ tmpFd, err := ioutil.TempFile("", "tofuproxy.*."+ext)
if err != nil {
log.Fatalln(err)
}
}
tmpFd.Close()
dstFn := tmpFd.Name() + ".png"
- cmd := exec.Command(CmdDJXL, tmpFd.Name(), dstFn)
+ cmd := exec.Command(cmdName, tmpFd.Name(), dstFn)
err = cmd.Run()
defer os.Remove(dstFn)
if err != nil {
w.WriteHeader(http.StatusOK)
w.Write(data)
fifos.SinkOther <- fmt.Sprintf(
- "%s %s\t%d\tJPEG XL transcoded to PNG",
+ "%s %s\t%d\t%s transcoded to PNG",
req.Method,
req.URL.String(),
http.StatusOK,
+ contentType,
)
return false, nil
}
+
+func RoundTranscodeJXL(
+ host string,
+ resp *http.Response,
+ w http.ResponseWriter,
+ req *http.Request,
+) (bool, error) {
+ return transcodeCmd2Png("image/jxl", "jxl", "djxl", resp, w, req)
+}
rounds.RoundDenyFonts,
rounds.RoundTranscodeWebP,
rounds.RoundTranscodeJXL,
+ rounds.RoundTranscodeAVIF,
rounds.RoundRedirectHTML,
} {
cont, err := round(host, resp, w, req)