2 tofuproxy -- flexible HTTP/HTTPS proxy, TLS terminator, X.509 TOFU
3 manager, WARC/geminispace browser
4 Copyright (C) 2021-2022 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/>.
35 Continuations []*Record
38 func (rec *Record) URI() string {
39 return strings.Trim(rec.Hdr.Get("WARC-Target-URI"), "<>")
42 func (rec *Record) TotalSize() int64 {
44 for _, r := range rec.Continuations {
50 type SelfRecordReader struct {
55 func (srr *SelfRecordReader) Read(p []byte) (n int, err error) {
56 n, err = srr.lr.Read(p)
63 func (srr *SelfRecordReader) Close() error {
64 return srr.rrr.Close()
67 func (rec *Record) selfReader(noHdr bool, offsets []Offset) (*SelfRecordReader, error) {
70 offset += int64(rec.HdrLen)
72 rrr, err := Open(rec.WARCPath, offsets, offset)
78 size += int64(rec.HdrLen)
80 return &SelfRecordReader{lr: &io.LimitedReader{R: rrr, N: size}, rrr: rrr}, nil
83 type RecordReader struct {
85 srrs []*SelfRecordReader
88 func (rec *Record) Reader(
90 warcOffsets map[string][]Offset,
91 ) (*RecordReader, error) {
92 srrs := make([]*SelfRecordReader, 0, 1+len(rec.Continuations))
93 rs := make([]io.Reader, 0, 1+len(rec.Continuations))
94 for i, r := range append([]*Record{rec}, rec.Continuations...) {
98 srr, err := r.selfReader(noHdr, warcOffsets[rec.WARCPath])
100 for _, srr := range srrs {
105 srrs = append(srrs, srr)
108 return &RecordReader{r: io.MultiReader(rs...), srrs: srrs}, nil
111 func (rr *RecordReader) Read(p []byte) (n int, err error) {
112 n, err = rr.r.Read(p)
119 func (rr *RecordReader) Close() error {
120 for _, srr := range rr.srrs {