Skip to content

Commit c6bf360

Browse files
committed
fix: return application/json for well-known and jwks
1 parent 2bfeb1a commit c6bf360

File tree

2 files changed

+39
-0
lines changed

2 files changed

+39
-0
lines changed

cmd/main.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,7 @@ func WellKnown(host string) func(http.ResponseWriter, *http.Request) {
247247
}
248248
b, _ := json.Marshal(wellknown)
249249
return func(w http.ResponseWriter, r *http.Request) {
250+
w.Header().Set("Content-Type", "application/json")
250251
w.Write(b)
251252
}
252253
}
@@ -257,6 +258,7 @@ func Jwks(s jwk.Set) (func(http.ResponseWriter, *http.Request), error) {
257258
return nil, fmt.Errorf("marshal jwks: %w", err)
258259
}
259260
return func(w http.ResponseWriter, r *http.Request) {
261+
w.Header().Set("Content-Type", "application/json")
260262
w.Write(jwksBytes)
261263
}, nil
262264
}

cmd/main_test.go

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
package main
2+
3+
import (
4+
"net/http/httptest"
5+
"testing"
6+
7+
"github.com/lestrrat-go/jwx/v3/jwk"
8+
)
9+
10+
func TestWellKnown(t *testing.T) {
11+
12+
wk := WellKnown("testing")
13+
14+
req := httptest.NewRequest("GET", "/", nil)
15+
w := httptest.NewRecorder()
16+
17+
wk(w, req)
18+
res := w.Result()
19+
20+
if contentType := res.Header.Get("Content-Type"); contentType != "application/json" {
21+
t.Errorf("expected content-type application/json, got %q", contentType)
22+
}
23+
}
24+
25+
func TestJwks(t *testing.T) {
26+
wk, _ := Jwks(jwk.NewSet())
27+
28+
req := httptest.NewRequest("GET", "/", nil)
29+
w := httptest.NewRecorder()
30+
31+
wk(w, req)
32+
res := w.Result()
33+
34+
if contentType := res.Header.Get("Content-Type"); contentType != "application/json" {
35+
t.Errorf("expected content-type application/json, got %q", contentType)
36+
}
37+
}

0 commit comments

Comments
 (0)