File tree Expand file tree Collapse file tree 2 files changed +16
-7
lines changed
packages/nextjs/src/middleware Expand file tree Collapse file tree 2 files changed +16
-7
lines changed Original file line number Diff line number Diff line change @@ -43,12 +43,15 @@ const createMockRequest = (
4343}
4444
4545const mockFetch = ( responseInit : Partial < Response > ) => {
46- global . fetch = jest . fn ( ) . mockResolvedValue (
47- new Response ( responseInit . body || "" , {
48- headers : new Headers ( responseInit . headers || { } ) ,
49- status : responseInit . status || 200 ,
50- } ) ,
51- )
46+ const response = new Response ( responseInit . body || "" , {
47+ headers : new Headers ( responseInit . headers || { } ) ,
48+ status : responseInit . status || 200 ,
49+ } )
50+ // simulate immutable headers like those returned by undici's fetch
51+ Object . defineProperty ( response . headers , "append" , { value : null } )
52+ Object . defineProperty ( response . headers , "set" , { value : null } )
53+ Object . defineProperty ( response . headers , "delete" , { value : null } )
54+ global . fetch = jest . fn ( ) . mockResolvedValue ( response )
5255}
5356
5457const createOptions = ( ) : OryMiddlewareOptions => ( {
Original file line number Diff line number Diff line change @@ -84,7 +84,7 @@ export async function proxyRequest(
8484 upstreamRequestHeaders . set ( "Ory-No-Custom-Domain-Redirect" , "true" )
8585
8686 // Fetch the upstream response
87- const upstreamResponse = await fetch ( upstreamUrl . toString ( ) , {
87+ let upstreamResponse = await fetch ( upstreamUrl . toString ( ) , {
8888 method : request . method ,
8989 headers : upstreamRequestHeaders ,
9090 body :
@@ -93,6 +93,12 @@ export async function proxyRequest(
9393 : null ,
9494 redirect : "manual" ,
9595 } )
96+ upstreamResponse = new Response ( upstreamResponse . body , {
97+ status : upstreamResponse . status ,
98+ statusText : upstreamResponse . statusText ,
99+ // response may have immutable headers
100+ headers : new Headers ( upstreamResponse . headers ) ,
101+ } )
96102
97103 // Delete headers that should not be forwarded
98104 defaultOmitHeaders . forEach ( ( header ) => {
You can’t perform that action at this time.
0 commit comments