aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFuwn <[email protected]>2026-02-28 04:36:36 -0800
committerFuwn <[email protected]>2026-02-28 04:36:36 -0800
commit22f616b517df9e686ca325d16de89ee3063a3b42 (patch)
tree6a0bd7ac869ce0e6e1e5ca4438246dc622e8bd13
parentchore(gitignore): ignore local thin validation artifacts (diff)
downloadplutia-test-22f616b517df9e686ca325d16de89ee3063a3b42.tar.xz
plutia-test-22f616b517df9e686ca325d16de89ee3063a3b42.zip
fix(api): match plc.directory success content-types in thin compatibility
-rw-r--r--internal/api/plc_compatibility_test.go43
-rw-r--r--internal/api/server.go10
2 files changed, 48 insertions, 5 deletions
diff --git a/internal/api/plc_compatibility_test.go b/internal/api/plc_compatibility_test.go
index a669f0c..8787902 100644
--- a/internal/api/plc_compatibility_test.go
+++ b/internal/api/plc_compatibility_test.go
@@ -78,6 +78,10 @@ func TestPLCCompatibilityGetDataShape(t *testing.T) {
t.Fatalf("status: got %d want 200", resp.StatusCode)
}
+ if got := resp.Header.Get("Content-Type"); got != "application/json; charset=utf-8" {
+ t.Fatalf("content-type mismatch: got %q want %q", got, "application/json; charset=utf-8")
+ }
+
var body map[string]any
if err := json.NewDecoder(resp.Body).Decode(&body); err != nil {
@@ -126,6 +130,10 @@ func TestPLCCompatibilityGetLogOrdered(t *testing.T) {
t.Fatalf("status: got %d want 200", resp.StatusCode)
}
+ if got := resp.Header.Get("Content-Type"); got != "application/json; charset=utf-8" {
+ t.Fatalf("content-type mismatch: got %q want %q", got, "application/json; charset=utf-8")
+ }
+
var ops []map[string]any
if err := json.NewDecoder(resp.Body).Decode(&ops); err != nil {
@@ -352,6 +360,41 @@ func TestPLCCompatibilityTombstonedDIDReturnsNotAvailable404(t *testing.T) {
check("/" + tombDID + "/data")
}
+func TestPLCCompatibilitySuccessContentTypesMatchUpstreamStyle(t *testing.T) {
+ ts, _, _, cleanup := newCompatibilityServer(t)
+ defer cleanup()
+
+ tests := []struct {
+ path string
+ want string
+ }{
+ {path: "/did:plc:alice", want: "application/did+ld+json; charset=utf-8"},
+ {path: "/did:plc:alice/data", want: "application/json; charset=utf-8"},
+ {path: "/did:plc:alice/log", want: "application/json; charset=utf-8"},
+ {path: "/did:plc:alice/log/last", want: "application/json; charset=utf-8"},
+ {path: "/did:plc:alice/log/audit", want: "application/json; charset=utf-8"},
+ }
+
+ for _, tc := range tests {
+ resp, err := http.Get(ts.URL + tc.path)
+ if err != nil {
+ t.Fatalf("get %s: %v", tc.path, err)
+ }
+
+ if resp.StatusCode != http.StatusOK {
+ _ = resp.Body.Close()
+ t.Fatalf("%s status: got %d want 200", tc.path, resp.StatusCode)
+ }
+
+ got := resp.Header.Get("Content-Type")
+ _ = resp.Body.Close()
+
+ if got != tc.want {
+ t.Fatalf("%s content-type mismatch: got %q want %q", tc.path, got, tc.want)
+ }
+ }
+}
+
func newCompatibilityServer(t *testing.T) (*httptest.Server, *storage.PebbleStore, []types.ExportRecord, func()) {
t.Helper()
diff --git a/internal/api/server.go b/internal/api/server.go
index 284c2b2..a3b4513 100644
--- a/internal/api/server.go
+++ b/internal/api/server.go
@@ -513,7 +513,7 @@ func (s *Server) handleGetDIDCompatibility(w http.ResponseWriter, r *http.Reques
status := http.StatusOK
deactivated := false
- writeJSONWithContentType(w, status, "application/did+ld+json", buildPLCDIDDocument(did, data, deactivated))
+ writeJSONWithContentType(w, status, "application/did+ld+json; charset=utf-8", buildPLCDIDDocument(did, data, deactivated))
}
func (s *Server) handleGetDIDLogCompatibility(w http.ResponseWriter, r *http.Request, did string) {
@@ -549,7 +549,7 @@ func (s *Server) handleGetDIDLogCompatibility(w http.ResponseWriter, r *http.Req
ops = append(ops, rec.Operation)
}
- writeJSONWithContentType(w, http.StatusOK, "application/json", ops)
+ writeJSONWithContentType(w, http.StatusOK, "application/json; charset=utf-8", ops)
}
func (s *Server) handleGetDIDLogLastCompatibility(w http.ResponseWriter, r *http.Request, did string) {
@@ -579,7 +579,7 @@ func (s *Server) handleGetDIDLogLastCompatibility(w http.ResponseWriter, r *http
return
}
- w.Header().Set("Content-Type", "application/json")
+ w.Header().Set("Content-Type", "application/json; charset=utf-8")
w.WriteHeader(http.StatusOK)
_, _ = w.Write(rec.Operation)
@@ -624,7 +624,7 @@ func (s *Server) handleGetDIDLogAuditCompatibility(w http.ResponseWriter, r *htt
})
}
- writeJSONWithContentType(w, http.StatusOK, "application/json", audit)
+ writeJSONWithContentType(w, http.StatusOK, "application/json; charset=utf-8", audit)
}
func (s *Server) handleGetDIDDataCompatibility(w http.ResponseWriter, r *http.Request, did string) {
@@ -665,7 +665,7 @@ func (s *Server) handleGetDIDDataCompatibility(w http.ResponseWriter, r *http.Re
return
}
- writeJSONWithContentType(w, http.StatusOK, "application/json", data)
+ writeJSONWithContentType(w, http.StatusOK, "application/json; charset=utf-8", data)
}
func (s *Server) resolveCompatibilityState(w http.ResponseWriter, r *http.Request, did string) (types.StateV1, bool) {