From e00e96d20589968885c9fbf358f4cedd14e1496c Mon Sep 17 00:00:00 2001 From: Mitar Date: Tue, 9 Jul 2024 15:26:42 +0200 Subject: [PATCH] fix: always issue headers in WriteIntrospectionResponse (#802) --- introspection_response_writer.go | 7 ++++--- introspection_response_writer_test.go | 1 + 2 files changed, 5 insertions(+), 3 deletions(-) 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), })