X-Git-Url: http://www.git.stargrave.org/?a=blobdiff_plain;f=rounds%2Fgemini.go;h=5c831d4e523ece81d6d40febdc21407ea7c166bf;hb=29146b48a23355805345a7b7a656809cf624bb85;hp=43cf422f5db1600c832c678b503db0dfead8d6e6;hpb=80f011b4e856b5598d17abb172687b228fac9641;p=tofuproxy.git diff --git a/rounds/gemini.go b/rounds/gemini.go index 43cf422..5c831d4 100644 --- a/rounds/gemini.go +++ b/rounds/gemini.go @@ -1,7 +1,7 @@ /* -tofuproxy -- flexible HTTP proxy, TLS terminator, X.509 certificates - manager, WARC/Gemini browser -Copyright (C) 2021 Sergey Matveev +tofuproxy -- flexible HTTP/HTTPS proxy, TLS terminator, X.509 TOFU + manager, WARC/geminispace browser +Copyright (C) 2021-2023 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 @@ -94,6 +94,12 @@ func RoundGemini( } paths := strings.Split(strings.TrimPrefix(req.URL.Path, "/"), "/") host, paths = paths[0], paths[1:] + if host == "gemini:" { + http.Redirect(w, req, strings.Join( + append([]string{GeminiEntrypoint}, paths[1:]...), "/", + ), http.StatusTemporaryRedirect) + return false, nil + } hostWithPort := host if !strings.Contains(hostWithPort, ":") { hostWithPort += GeminiPort @@ -149,7 +155,7 @@ func RoundGemini( fmt.Sprintf( ` %d (%s) redirection -Redirection to %s`, +%s`, code, codeName, u, u, ))) fifos.LogRedir <- fmt.Sprintf( @@ -157,27 +163,37 @@ func RoundGemini( ) return false, nil } + msg := fmt.Sprintf( + "%s %s\t%d (%s)\t%s", + req.Method, req.URL, + code, codeName, + cols[1], + ) if 40 <= code && code <= 49 { w.Header().Add("Content-Type", "text/plain") w.WriteHeader(http.StatusBadGateway) fmt.Fprintf(w, "%s\n%d (%s)\n", cols[1], code, codeName) + fifos.LogNonOK <- msg return false, nil } if 50 <= code && code <= 59 { w.Header().Add("Content-Type", "text/plain") w.WriteHeader(http.StatusBadGateway) fmt.Fprintf(w, "%s\n%d (%s)\n", cols[1], code, codeName) + fifos.LogNonOK <- msg return false, nil } if 60 <= code && code <= 69 { w.Header().Add("Content-Type", "text/plain") w.WriteHeader(http.StatusUnauthorized) fmt.Fprintf(w, "%s\n%d (%s)\n", cols[1], code, codeName) + fifos.LogNonOK <- msg return false, nil } if !(20 <= code && code <= 29) { err = fmt.Errorf("unknown response code: %d", code) log.Printf("%s: %s\n", req.URL, err) + fifos.LogNonOK <- msg return false, err } contentType := strings.Split(strings.TrimRight(cols[1], "\r\n"), ";")[0] @@ -253,6 +269,7 @@ func RoundGemini( } buf.WriteString("\n") _, err = w.Write(buf.Bytes()) + fifos.LogOK <- msg return false, err } w.Header().Add("Content-Type", contentType) @@ -261,5 +278,6 @@ func RoundGemini( if err != nil { log.Printf("%s: can not read response body: %+v\n", req.URL, err) } + fifos.LogOK <- msg return false, err }