/*
-tofuproxy -- flexible HTTP proxy, TLS terminator, X.509 certificates
- manager, WARC/Gemini browser
+tofuproxy -- flexible HTTP/HTTPS proxy, TLS terminator, X.509 TOFU
+ manager, WARC/geminispace browser
Copyright (C) 2021 Sergey Matveev <stargrave@stargrave.org>
This program is free software: you can redistribute it and/or modify
}
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
log.Printf("%s: can not dial: %+v\n", req.URL, err)
return false, err
}
- _, err = fmt.Fprintf(
- conn, "%s%s/%s\r\n",
- SchemeGemini, host, strings.Join(paths, "/"),
- )
- if err != nil {
+ query := fmt.Sprintf("%s%s/%s", SchemeGemini, host, strings.Join(paths, "/"))
+ if req.URL.RawQuery != "" {
+ query += "?" + req.URL.RawQuery
+ }
+ if _, err = conn.Write([]byte(query + "\r\n")); err != nil {
log.Printf("%s: can not send request: %+v\n", req.URL, err)
return false, err
}