X-Git-Url: http://www.git.stargrave.org/?a=blobdiff_plain;f=rounds%2Fgemini.go;h=71da97f361bfe33526a696be30e00ac0b2177b62;hb=HEAD;hp=b3ed3205f2aabdc974a75407285aba429a4babb2;hpb=a8ff9a396372aa83fd42e2fd61095e7888c556ab;p=tofuproxy.git diff --git a/rounds/gemini.go b/rounds/gemini.go index b3ed320..71da97f 100644 --- a/rounds/gemini.go +++ b/rounds/gemini.go @@ -1,20 +1,18 @@ -/* -tofuproxy -- flexible HTTP/HTTPS proxy, TLS terminator, X.509 TOFU - manager, WARC/geminispace browser -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 @@ -126,7 +124,7 @@ func RoundGemini( log.Printf("%s: can not read response: %+v\n", req.URL, err) return false, err } - cols := strings.SplitN(rawResp, " ", 2) + cols := strings.SplitN(strings.TrimRight(rawResp, "\r\n"), " ", 2) if len(cols) < 2 { err = fmt.Errorf("invalid response format: %s", rawResp) log.Printf("%s: %s\n", req.URL, err) @@ -151,13 +149,9 @@ func RoundGemini( w.Header().Add("Content-Type", "text/html") w.WriteHeader(http.StatusOK) u := geminifyURL(host, cols[1], paths...) - w.Write([]byte( - fmt.Sprintf( - ` + fmt.Fprintf(w, ` %d (%s) redirection -Redirection to %s`, - code, codeName, u, u, - ))) +%s`, code, codeName, u, u) fifos.LogRedir <- fmt.Sprintf( "%s %s\t%d\t%s", req.Method, req.URL, code, cols[1], ) @@ -225,20 +219,30 @@ func RoundGemini( fmt.Fprintf(&buf, "%s\n", line) continue } - if strings.HasPrefix(line, "=> ") { + if strings.HasPrefix(line, "=>") { + line = strings.TrimLeft(line[2:], " ") cols = strings.Fields(line) - u := geminifyURL(host, cols[1], paths...) + u1 := geminifyURL(host, cols[0], paths...) + u2 := geminifyURL(host, cols[0]) switch len(cols) { - case 2: + case 1: fmt.Fprintf( - &buf, "%s
\n", - u, html.EscapeString(cols[1]), + &buf, "%s", + u1, html.EscapeString(cols[0]), ) + if u1 != u2 { + fmt.Fprintf(&buf, " [2]", u2) + } + fmt.Fprintf(&buf, "
\n") default: fmt.Fprintf( - &buf, "%s (%s)
\n", - u, html.EscapeString(strings.Join(cols[2:], " ")), cols[1], + &buf, "%s", + u1, html.EscapeString(strings.Join(cols[1:], " ")), ) + if u1 != u2 { + fmt.Fprintf(&buf, " [2]", u2) + } + fmt.Fprintf(&buf, "(%s)
\n", cols[0]) } continue } @@ -254,10 +258,6 @@ func RoundGemini( fmt.Fprintf(&buf, "

%s

\n", html.EscapeString(line[4:])) continue } - if strings.HasPrefix(line, "* ") { - fmt.Fprintf(&buf, "• %s\n", html.EscapeString(line[2:])) - continue - } if strings.HasPrefix(line, "> ") { fmt.Fprintf( &buf, "
%s
\n",