File tree Expand file tree Collapse file tree 1 file changed +12
-3
lines changed
examples/unit-test-a-worker Expand file tree Collapse file tree 1 file changed +12
-3
lines changed Original file line number Diff line number Diff line change 1+ // Add any more global vars (like Request, Response) to the below list as they are used
2+ /* global addEventListener fetch Response Headers */
3+
14addEventListener ( "fetch" , e => {
25 e . respondWith ( fetchAndAddHeader ( e . request ) ) ;
36} ) ;
47
58async function fetchAndAddHeader ( request ) {
69 const response = await fetch ( request ) ;
710
11+ const headers = new Headers ( response . headers ) ;
12+
813 if ( response . status === 200 ) {
9- response . headers . set ( "Foo" , "Bar" ) ;
14+ headers . set ( "Foo" , "Bar" ) ;
1015 } else {
11- response . headers . set ( "Foo" , "Not Bar" ) ;
16+ headers . set ( "Foo" , "Not Bar" ) ;
1217 }
1318
14- return response ;
19+ return new Response ( response . body , {
20+ headers : headers ,
21+ status : response . status ,
22+ statusText : response . statusText ,
23+ } ) ;
1524}
You can’t perform that action at this time.
0 commit comments