2 tofuproxy -- flexible HTTP/HTTPS proxy, TLS terminator, X.509 TOFU
3 manager, WARC/geminispace browser
4 Copyright (C) 2021-2023 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 isFeeder(req *http.Request) bool {
48 if strings.Contains(req.Header.Get("User-Agent"), "newsboat/") {
51 if strings.Contains(req.Header.Get("User-Agent"), "stargrave.org-feeder/") {
57 func RoundRedirectHTML(
60 w http.ResponseWriter,
63 if req.Method != http.MethodGet {
67 switch resp.StatusCode {
68 case http.StatusMovedPermanently, http.StatusPermanentRedirect:
69 redirType = "permanent"
70 case http.StatusFound, http.StatusSeeOther, http.StatusTemporaryRedirect:
74 if _, ok := imageExts[filepath.Ext(req.URL.Path)]; ok {
77 redirType = "temporary"
82 w.Header().Add("Content-Type", "text/html")
83 w.WriteHeader(http.StatusOK)
84 location := resp.Header.Get("Location")
87 <html><head><title>%d %s: %s redirection</title></head>
88 <body><a href="%s">%s</a></body></html>`,
89 resp.StatusCode, http.StatusText(resp.StatusCode),
90 redirType, location, location,
92 fifos.LogRedir <- fmt.Sprintf(
93 "%s %s\t%s\t%s", req.Method, req.URL, resp.Status, location,