@@ -56,4 +56,46 @@ describe('content-disposition', () => {
5656 expect ( resp . status ) . to . equal ( 200 )
5757 expect ( resp . headers . get ( 'Content-Disposition' ) ) . to . include ( 'attachment' )
5858 } )
59+
60+ it ( 'should default to the CID for the car file name' , async ( ) => {
61+ const obj = {
62+ hello : 'world'
63+ }
64+ const c = dagCbor ( helia )
65+ const cid = await c . add ( obj )
66+
67+ const resp = await fetch ( `ipfs://${ cid } /?format=car` )
68+ expect ( resp ) . to . be . ok ( )
69+ expect ( resp . status ) . to . equal ( 200 )
70+ expect ( resp . headers . get ( 'Content-Disposition' ) ) . to . include ( 'attachment' )
71+ expect ( resp . headers . get ( 'Content-Disposition' ) ) . to . include ( `filename="${ cid } .car"` )
72+ } )
73+
74+ it ( 'should respect a filename for the car file name' , async ( ) => {
75+ const obj = {
76+ hello : 'world'
77+ }
78+ const c = dagCbor ( helia )
79+ const cid = await c . add ( obj )
80+
81+ const resp = await fetch ( `ipfs://${ cid } /?filename=my-car.car&format=car` )
82+ expect ( resp ) . to . be . ok ( )
83+ expect ( resp . status ) . to . equal ( 200 )
84+ expect ( resp . headers . get ( 'Content-Disposition' ) ) . to . include ( 'attachment' )
85+ expect ( resp . headers . get ( 'Content-Disposition' ) ) . to . include ( 'filename="my-car.car"' )
86+ } )
87+
88+ it ( 'should respect a filename for the car file name with many trailing slashes' , async ( ) => {
89+ const obj = {
90+ hello : 'world'
91+ }
92+ const c = dagCbor ( helia )
93+ const cid = await c . add ( obj )
94+
95+ const resp = await fetch ( `ipfs://${ cid } ///////?filename=my-car.car&format=car` )
96+ expect ( resp ) . to . be . ok ( )
97+ expect ( resp . status ) . to . equal ( 200 )
98+ expect ( resp . headers . get ( 'Content-Disposition' ) ) . to . include ( 'attachment' )
99+ expect ( resp . headers . get ( 'Content-Disposition' ) ) . to . include ( 'filename="my-car.car"' )
100+ } )
59101} )
0 commit comments