X-Git-Url: http://www.git.stargrave.org/?a=blobdiff_plain;f=rounds%2FredirectHTML.go;h=4f8dec3c437f29de611d7039c1e94067a7efb7ea;hb=aebff9ec61ff98c73f83f73f081401038699d37f;hp=d13047a14dc37a139c9d77fb1d6623765866df28;hpb=0c0a261a6ef4fddfc34a9150005f7964cc69c420;p=tofuproxy.git diff --git a/rounds/redirectHTML.go b/rounds/redirectHTML.go index d13047a..4f8dec3 100644 --- a/rounds/redirectHTML.go +++ b/rounds/redirectHTML.go @@ -1,19 +1,18 @@ -/* -tofuproxy -- flexible HTTP/WARC proxy with TLS certificates management -Copyright (C) 2021 Sergey Matveev - -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 . -*/ +// tofuproxy -- flexible HTTP/HTTPS proxy, TLS terminator, X.509 TOFU +// manager, WARC/geminispace browser +// Copyright (C) 2021-2024 Sergey Matveev +// +// 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 . package rounds @@ -43,8 +42,14 @@ var imageExts = map[string]struct{}{ ".webp": {}, } -func isNewsboat(req *http.Request) bool { - return strings.Contains(req.Header.Get("User-Agent"), "newsboat/") +func isFeeder(req *http.Request) bool { + if strings.Contains(req.Header.Get("User-Agent"), "newsboat/") { + return true + } + if strings.Contains(req.Header.Get("User-Agent"), "stargrave.org-feeder/") { + return true + } + return false } func RoundRedirectHTML( @@ -61,7 +66,7 @@ func RoundRedirectHTML( case http.StatusMovedPermanently, http.StatusPermanentRedirect: redirType = "permanent" case http.StatusFound, http.StatusSeeOther, http.StatusTemporaryRedirect: - if isNewsboat(req) { + if isFeeder(req) { return true, nil } if _, ok := imageExts[filepath.Ext(req.URL.Path)]; ok { @@ -75,13 +80,13 @@ func RoundRedirectHTML( w.Header().Add("Content-Type", "text/html") w.WriteHeader(http.StatusOK) location := resp.Header.Get("Location") - w.Write([]byte( - fmt.Sprintf( - `%d %s: %s redirection -Redirection to %s`, - resp.StatusCode, http.StatusText(resp.StatusCode), - redirType, location, location, - ))) + fmt.Fprintf( + w, ` +%d %s: %s redirection +%s`, + resp.StatusCode, http.StatusText(resp.StatusCode), + redirType, location, location, + ) fifos.LogRedir <- fmt.Sprintf( "%s %s\t%s\t%s", req.Method, req.URL, resp.Status, location, )