2 tofuproxy -- flexible HTTP proxy, TLS terminator, X.509 certificates
3 manager, WARC/Gemini 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/warc"
30 func listWARCs(p string) {
32 fd, err := os.OpenFile(p, os.O_WRONLY|os.O_APPEND, os.FileMode(0666))
37 for warcPath, uris := range warc.WARCs {
40 warcPath, len(uris), len(warc.WARCs[warcPath]),
48 func addWARC(p string) {
50 fd, err := os.OpenFile(p, os.O_RDONLY, os.FileMode(0666))
54 var warcPaths []string
55 scanner := bufio.NewScanner(fd)
59 warcPaths = append(warcPaths, t)
63 for _, warcPath := range warcPaths {
64 if warcPath == "SAVE" {
65 if err = warc.SaveIndexes(); err != nil {
66 log.Printf("%s: can not save index %s: %+v\n", p, warcPath, err)
70 if _, exists := warc.WARCs[warcPath]; exists {
73 log.Printf("%s: adding WARC %s\n", p, warcPath)
74 err = warc.Add(warcPath)
76 log.Printf("%s: can not open %s: %+v\n", p, warcPath, err)
80 "%s: %s: added %d URIs %d segments\n",
82 len(warc.WARCs[warcPath]),
83 len(warc.WARCsOffsets[warcPath]),