@@ -129,6 +129,43 @@ test("Fedify should handle notAcceptable and return 406", async () => {
129129 await fastify . close ( ) ;
130130} ) ;
131131
132+ test ( "Fedify should create a fresh 406 response for each request" , async ( ) => {
133+ const fastify = Fastify ( { logger : false } ) ;
134+ const federation = createFederation < void > ( { kv : new MemoryKvStore ( ) } ) ;
135+
136+ federation . setActorDispatcher (
137+ "/users/{identifier}" ,
138+ ( _ctx : RequestContext < void > , identifier : string ) => {
139+ return new Person ( {
140+ id : new URL ( `https://example.com/users/${ identifier } ` ) ,
141+ preferredUsername : identifier ,
142+ name : `User ${ identifier } ` ,
143+ } ) ;
144+ } ,
145+ ) ;
146+
147+ await fastify . register ( fedifyPlugin , { federation } ) ;
148+ await fastify . ready ( ) ;
149+
150+ const firstResponse = await fastify . inject ( {
151+ method : "GET" ,
152+ url : "/users/alice" ,
153+ headers : { "Accept" : "text/html" } ,
154+ } ) ;
155+ const secondResponse = await fastify . inject ( {
156+ method : "GET" ,
157+ url : "/users/alice" ,
158+ headers : { "Accept" : "text/html" } ,
159+ } ) ;
160+
161+ assert . equal ( firstResponse . statusCode , 406 ) ;
162+ assert . equal ( firstResponse . body , "Not Acceptable" ) ;
163+ assert . equal ( secondResponse . statusCode , 406 ) ;
164+ assert . equal ( secondResponse . body , "Not Acceptable" ) ;
165+
166+ await fastify . close ( ) ;
167+ } ) ;
168+
132169test ( "Fedify should handle notAcceptable with custom error handler" , async ( ) => {
133170 const fastify = Fastify ( { logger : false } ) ;
134171 const federation = createFederation < void > ( { kv : new MemoryKvStore ( ) } ) ;
0 commit comments