diff options
| author | Paul Buetow <paul@buetow.org> | 2026-04-14 10:01:43 +0300 |
|---|---|---|
| committer | Paul Buetow <paul@buetow.org> | 2026-04-14 10:01:43 +0300 |
| commit | 4d9004ab31a6064af741fbb73758bd8844964c6f (patch) | |
| tree | 38a7f09840b6cd8774ba5b4ce24b373d4cc1de26 /internal/daemon | |
| parent | 385cc685ab8f5312225342c66d29aaa3bf008a45 (diff) | |
z2: HTTP report query aliases and Gemtext Content-Type
Accept Category, Metric, and OutputFormat as alternate query keys
alongside category, metric, output-format. Serve Gemtext reports
with text/gemini; assert Content-Type in daemon tests.
Builds on y2 daemon GET /report reusing ParseReportQuery and
WriteReports.
Made-with: Cursor
Diffstat (limited to 'internal/daemon')
| -rw-r--r-- | internal/daemon/daemon.go | 2 | ||||
| -rw-r--r-- | internal/daemon/daemon_test.go | 42 |
2 files changed, 44 insertions, 0 deletions
diff --git a/internal/daemon/daemon.go b/internal/daemon/daemon.go index 4e2402f..a4b1a3e 100644 --- a/internal/daemon/daemon.go +++ b/internal/daemon/daemon.go @@ -101,6 +101,8 @@ func reportContentType(f goprecords.OutputFormat) string { switch f { case goprecords.FormatMarkdown: return "text/markdown; charset=utf-8" + case goprecords.FormatGemtext: + return "text/gemini; charset=utf-8" default: return "text/plain; charset=utf-8" } diff --git a/internal/daemon/daemon_test.go b/internal/daemon/daemon_test.go index 38878fa..b140c9e 100644 --- a/internal/daemon/daemon_test.go +++ b/internal/daemon/daemon_test.go @@ -54,6 +54,9 @@ func TestReport(t *testing.T) { if res.StatusCode != http.StatusOK { t.Fatalf("status %d", res.StatusCode) } + if ct := res.Header.Get("Content-Type"); ct != "text/plain; charset=utf-8" { + t.Fatalf("Content-Type %q", ct) + } b, err := io.ReadAll(res.Body) if err != nil { t.Fatal(err) @@ -63,6 +66,45 @@ func TestReport(t *testing.T) { } } +func TestReportQueryAliases(t *testing.T) { + fixtures := filepath.Join("..", "..", "fixtures") + srv := httptest.NewServer(Handler(fixtures)) + defer srv.Close() + res, err := http.Get(srv.URL + "/report?Category=Host&Metric=Uptime&limit=2&OutputFormat=Markdown") + if err != nil { + t.Fatal(err) + } + defer res.Body.Close() + if res.StatusCode != http.StatusOK { + t.Fatalf("status %d", res.StatusCode) + } + if ct := res.Header.Get("Content-Type"); ct != "text/markdown; charset=utf-8" { + t.Fatalf("Content-Type %q", ct) + } + b, _ := io.ReadAll(res.Body) + body := string(b) + if !strings.Contains(body, "# Top") || !strings.Contains(body, "```") { + t.Fatalf("expected markdown heading and fence, got %q", b) + } +} + +func TestReportGemtextContentType(t *testing.T) { + fixtures := filepath.Join("..", "..", "fixtures") + srv := httptest.NewServer(Handler(fixtures)) + defer srv.Close() + res, err := http.Get(srv.URL + "/report?output-format=Gemtext&limit=2") + if err != nil { + t.Fatal(err) + } + defer res.Body.Close() + if res.StatusCode != http.StatusOK { + t.Fatalf("status %d", res.StatusCode) + } + if ct := res.Header.Get("Content-Type"); ct != "text/gemini; charset=utf-8" { + t.Fatalf("Content-Type %q", ct) + } +} + func TestReportBadQuery(t *testing.T) { srv := httptest.NewServer(Handler(t.TempDir())) defer srv.Close() |
