From 2dd0a77b6e0569a8c5186696259a1942eec97990 Mon Sep 17 00:00:00 2001 From: Trevor Slocum Date: Sat, 21 Nov 2020 21:13:49 -0800 Subject: [PATCH] Follow redirections --- pkg/gmitohtml/convert.go | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/pkg/gmitohtml/convert.go b/pkg/gmitohtml/convert.go index b929c7f..06dedf8 100644 --- a/pkg/gmitohtml/convert.go +++ b/pkg/gmitohtml/convert.go @@ -124,13 +124,15 @@ func fetch(u string, clientCertFile string, clientCertKey string) ([]byte, []byt if requestURL.Scheme == "" { requestURL.Scheme = "gemini" } - if strings.IndexRune(requestURL.Host, ':') == -1 { - requestURL.Host += ":1965" + + host := requestURL.Host + if strings.IndexRune(host, ':') == -1 { + host += ":1965" } tlsConfig := &tls.Config{} - conn, err := tls.Dial("tcp", requestURL.Host, tlsConfig) + conn, err := tls.Dial("tcp", host, tlsConfig) if err != nil { return nil, nil, err } @@ -192,7 +194,7 @@ func handleRequest(writer http.ResponseWriter, request *http.Request) { if len(header) > 0 && header[0] == '3' { split := bytes.SplitN(header, []byte(" "), 2) if len(split) == 2 { - writer.Header().Set("Location", rewriteURL(string(split[1]), request.URL)) + http.Redirect(writer, request, rewriteURL(string(split[1]), request.URL), http.StatusTemporaryRedirect) return } }