2 tofuproxy -- flexible HTTP/WARC proxy with TLS certificates management
3 Copyright (C) 2021 Sergey Matveev <stargrave@stargrave.org>
5 This program is free software: you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation, version 3 of the License.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program. If not, see <http://www.gnu.org/licenses/>.
26 "go.stargrave.org/tofuproxy/warc"
29 func listWARCs(p string) {
31 fd, err := os.OpenFile(p, os.O_WRONLY|os.O_APPEND, os.FileMode(0666))
36 for warcPath, uris := range warc.WARCs {
39 warcPath, len(uris), len(warc.WARCs[warcPath]),
47 func addWARC(p string) {
49 fd, err := os.OpenFile(p, os.O_RDONLY, os.FileMode(0666))
53 var warcPaths []string
54 scanner := bufio.NewScanner(fd)
58 warcPaths = append(warcPaths, t)
62 for _, warcPath := range warcPaths {
63 if warcPath == "SAVE" {
64 if err = warc.SaveIndexes(); err != nil {
65 log.Printf("%s: can not save index %s: %+v\n", p, warcPath, err)
69 if _, exists := warc.WARCs[warcPath]; exists {
72 log.Printf("%s: adding WARC %s\n", p, warcPath)
73 err = warc.Add(warcPath)
75 log.Printf("%s: can not open %s: %+v\n", p, warcPath, err)
79 "%s: %s: added %d URIs %d segments\n",
81 len(warc.WARCs[warcPath]),
82 len(warc.WARCsOffsets[warcPath]),