diff --git a/introspection_response_writer.go b/introspection_response_writer.go index 5711d2b6..e0a3763e 100644 --- a/introspection_response_writer.go +++ b/introspection_response_writer.go @@ -179,6 +179,10 @@ func (f *Fosite) WriteIntrospectionError(ctx context.Context, rw http.ResponseWr // "active": false // } func (f *Fosite) WriteIntrospectionResponse(ctx context.Context, rw http.ResponseWriter, r IntrospectionResponder) { + rw.Header().Set("Content-Type", "application/json;charset=UTF-8") + rw.Header().Set("Cache-Control", "no-store") + rw.Header().Set("Pragma", "no-cache") + if !r.IsActive() { _ = json.NewEncoder(rw).Encode(&struct { Active bool `json:"active"` @@ -226,8 +230,5 @@ func (f *Fosite) WriteIntrospectionResponse(ctx context.Context, rw http.Respons response["username"] = r.GetAccessRequester().GetSession().GetUsername() } - rw.Header().Set("Content-Type", "application/json;charset=UTF-8") - rw.Header().Set("Cache-Control", "no-store") - rw.Header().Set("Pragma", "no-cache") _ = json.NewEncoder(rw).Encode(response) } diff --git a/introspection_response_writer_test.go b/introspection_response_writer_test.go index b1738cef..a7754486 100644 --- a/introspection_response_writer_test.go +++ b/introspection_response_writer_test.go @@ -53,6 +53,7 @@ func TestWriteIntrospectionResponse(t *testing.T) { rw := internal.NewMockResponseWriter(c) rw.EXPECT().Write(gomock.Any()).AnyTimes() + rw.EXPECT().Header().AnyTimes().Return(http.Header{}) f.WriteIntrospectionResponse(context.Background(), rw, &IntrospectionResponse{ AccessRequester: NewAccessRequest(nil), })