@@ -490,6 +490,11 @@ func writeResponse(api API, ctx Context, status int, ct string, body any) error
490490 ct , err = api .Negotiate (ctx .Header ("Accept" ))
491491 if err != nil {
492492 notAccept := NewErrorWithContext (ctx , http .StatusNotAcceptable , "unable to marshal response" , err )
493+ ct := "application/json"
494+ if ctf , ok := notAccept .(ContentTypeFilter ); ok {
495+ ct = ctf .ContentType (ct )
496+ }
497+ ctx .SetHeader ("Content-Type" , ct )
493498 if e := transformAndWrite (api , ctx , http .StatusNotAcceptable , "application/json" , notAccept ); e != nil {
494499 return e
495500 }
@@ -499,6 +504,8 @@ func writeResponse(api API, ctx Context, status int, ct string, body any) error
499504 if ctf , ok := body .(ContentTypeFilter ); ok {
500505 ct = ctf .ContentType (ct )
501506 }
507+
508+ ctx .SetHeader ("Content-Type" , ct )
502509 }
503510
504511 if err := transformAndWrite (api , ctx , status , ct , body ); err != nil {
@@ -543,8 +550,6 @@ func transformAndWrite(api API, ctx Context, status int, ct string, body any) er
543550 }
544551 }
545552
546- ctx .SetHeader ("Content-Type" , ct )
547-
548553 return nil
549554}
550555
0 commit comments