summaryrefslogtreecommitdiff
path: root/gemini
diff options
context:
space:
mode:
authortjpcc <tjp@ctrl-c.club>2023-10-30 13:41:59 -0600
committertjpcc <tjp@ctrl-c.club>2023-10-30 13:42:12 -0600
commit634b82d24335564139b43617d641d6880219e321 (patch)
tree3c22ada00c48d6cef34aa63a0c1558857363790f /gemini
parent3f1973b621ad10e783955244d0d9f39176feda45 (diff)
support spartan in auto-atom conversion middleware
Diffstat (limited to 'gemini')
-rw-r--r--gemini/gemtext/atomconv/convert.go29
1 files changed, 24 insertions, 5 deletions
diff --git a/gemini/gemtext/atomconv/convert.go b/gemini/gemtext/atomconv/convert.go
index 30228f3..43a1939 100644
--- a/gemini/gemtext/atomconv/convert.go
+++ b/gemini/gemtext/atomconv/convert.go
@@ -12,9 +12,11 @@ import (
"strings"
"time"
+ "tildegit.org/tjp/sliderule"
"tildegit.org/tjp/sliderule/gemini"
"tildegit.org/tjp/sliderule/gemini/gemtext"
"tildegit.org/tjp/sliderule/internal/types"
+ "tildegit.org/tjp/sliderule/spartan"
)
// Convert turns a gemini document to Atom format.
@@ -43,7 +45,7 @@ func Convert(wr io.Writer, doc gemtext.Document, location *url.URL) error {
// gemini://gemini.circumlunar.space/docs/companion/subscription.gmi
var Auto = types.Middleware(func(h types.Handler) types.Handler {
return types.HandlerFunc(func(ctx context.Context, request *types.Request) *types.Response {
- if request.Scheme != "gemini" || !strings.HasSuffix(request.Path, ".atom") {
+ if !(request.Scheme == "gemini" || request.Scheme == "spartan") || !strings.HasSuffix(request.Path, ".atom") {
return h.Handle(ctx, request)
}
@@ -53,7 +55,24 @@ var Auto = types.Middleware(func(h types.Handler) types.Handler {
r.URL = &u
response := h.Handle(ctx, &r)
- if response.Status != gemini.StatusSuccess {
+
+ var (
+ success sliderule.Status
+ buildSuccess func(string, io.Reader) *sliderule.Response
+ buildFailure func(error) *sliderule.Response
+ )
+ switch request.Scheme {
+ case "gemini":
+ success = gemini.StatusSuccess
+ buildSuccess = gemini.Success
+ buildFailure = gemini.Failure
+ case "spartan":
+ success = spartan.StatusSuccess
+ buildSuccess = spartan.Success
+ buildFailure = spartan.ServerError
+ }
+
+ if response.Status != success {
return response
}
@@ -68,14 +87,14 @@ var Auto = types.Middleware(func(h types.Handler) types.Handler {
doc, err := gemtext.Parse(response.Body)
if err != nil {
- return gemini.Failure(err)
+ return buildFailure(err)
}
buf := &bytes.Buffer{}
if err := Convert(buf, doc, request.URL); err != nil {
- return gemini.Failure(err)
+ return buildFailure(err)
}
- return gemini.Success("application/atom+xml; charset=utf-8", buf)
+ return buildSuccess("application/atom+xml; charset=utf-8", buf)
})
})