Skip to content

Commit

Permalink
fix: always issue headers in WriteIntrospectionResponse
Browse files Browse the repository at this point in the history
  • Loading branch information
mitar authored and aeneasr committed Jul 9, 2024
1 parent 576230a commit 8b09764
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
7 changes: 4 additions & 3 deletions introspection_response_writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down Expand Up @@ -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)
}
1 change: 1 addition & 0 deletions introspection_response_writer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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),
})
Expand Down

0 comments on commit 8b09764

Please sign in to comment.