2 tofuproxy -- flexible HTTP/HTTPS proxy, TLS terminator, X.509 TOFU
3 manager, WARC/geminispace browser
4 Copyright (C) 2021 Sergey Matveev <stargrave@stargrave.org>
6 This program is free software: you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation, version 3 of the License.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
27 "go.stargrave.org/tofuproxy/fifos"
30 var imageExts = map[string]struct{}{
47 func isNewsboat(req *http.Request) bool {
48 return strings.Contains(req.Header.Get("User-Agent"), "newsboat/")
51 func RoundRedirectHTML(
54 w http.ResponseWriter,
57 if req.Method != http.MethodGet {
61 switch resp.StatusCode {
62 case http.StatusMovedPermanently, http.StatusPermanentRedirect:
63 redirType = "permanent"
64 case http.StatusFound, http.StatusSeeOther, http.StatusTemporaryRedirect:
68 if _, ok := imageExts[filepath.Ext(req.URL.Path)]; ok {
71 redirType = "temporary"
76 w.Header().Add("Content-Type", "text/html")
77 w.WriteHeader(http.StatusOK)
78 location := resp.Header.Get("Location")
82 <html><head><title>%d %s: %s redirection</title></head>
83 <body><a href="%s">%s</a></body></html>`,
84 resp.StatusCode, http.StatusText(resp.StatusCode),
85 redirType, location, location,
87 fifos.LogRedir <- fmt.Sprintf(
88 "%s %s\t%s\t%s", req.Method, req.URL, resp.Status, location,