@@ -45,6 +45,17 @@ const md5Buffer = new Uint8Array([
4545 0x9a , 0x03 , 0x64 , 0xb9 , 0xe9 , 0x9b , 0xb4 , 0x80 , 0xdd , 0x25 , 0xe1 , 0xf0 , 0x28 ,
4646 0x4c , 0x85 , 0x55 ,
4747] ) ;
48+ // Test SHA1 checksum
49+ const sha1Buffer = new Uint8Array ( [
50+ 0x2a , 0x03 , 0x64 , 0xb9 , 0xe9 , 0x9b , 0xb4 , 0x80 , 0xdd , 0x25 , 0xe1 , 0xf0 , 0x28 ,
51+ 0x4c , 0x85 , 0x55 , 0x11 , 0x22 , 0x33 , 0x44 ,
52+ ] ) ;
53+ // Test SHA256 checksum
54+ const sha256Buffer = new Uint8Array ( [
55+ 0x3a , 0x03 , 0x64 , 0xb9 , 0xe9 , 0x9b , 0xb4 , 0x80 , 0xdd , 0x25 , 0xe1 , 0xf0 , 0x28 ,
56+ 0x4c , 0x85 , 0x55 , 0x11 , 0x22 , 0x33 , 0x44 , 0x55 , 0x66 , 0x77 , 0x88 , 0x99 , 0xaa ,
57+ 0xbb , 0xcc , 0xdd , 0xee , 0xff , 0x00 ,
58+ ] ) ;
4859const objResponse = {
4960 name : key ,
5061 version : 'objectVersion' ,
@@ -359,10 +370,19 @@ export default {
359370 } ) ;
360371 }
361372 }
362- case 'md5checksum' : {
373+ case 'multipleChecksums' : {
374+ // Convert buffers to hex strings as expected by Cap'n Proto JSON codec
375+ const toHex = ( buffer ) =>
376+ Array . from ( buffer , ( b ) => b . toString ( 16 ) . padStart ( 2 , '0' ) ) . join (
377+ ''
378+ ) ;
363379 return Response . json ( {
364380 ...objResponse ,
365- md5 : md5Buffer ,
381+ checksums : {
382+ 0 : toHex ( md5Buffer ) , // md5
383+ 1 : toHex ( sha1Buffer ) , // sha1
384+ 2 : toHex ( sha256Buffer ) , // sha256
385+ } ,
366386 } ) ;
367387 }
368388 }
@@ -554,6 +574,24 @@ export default {
554574 body,
555575 } ) ;
556576 }
577+ case 'multipleChecksums' : {
578+ // Return HEAD response with multiple checksums
579+ // Convert buffers to hex strings as expected by Cap'n Proto JSON codec
580+ const toHex = ( buffer ) =>
581+ Array . from ( buffer , ( b ) => b . toString ( 16 ) . padStart ( 2 , '0' ) ) . join (
582+ ''
583+ ) ;
584+ return buildGetResponse ( {
585+ head : {
586+ checksums : {
587+ 0 : toHex ( md5Buffer ) , // md5
588+ 1 : toHex ( sha1Buffer ) , // sha1
589+ 2 : toHex ( sha256Buffer ) , // sha256
590+ } ,
591+ } ,
592+ body : jsonRequest . method === 'get' ? body : undefined ,
593+ } ) ;
594+ }
557595 }
558596 throw new Error ( 'Unexpected GET' ) ;
559597 }
@@ -893,11 +931,15 @@ export default {
893931 }
894932 // Checksums
895933 {
896- // This exists purely to test the instrumentation
897- let resp = await env . BUCKET . put ( 'md5checksum ' , body , {
934+ // This tests the instrumentation with multiple checksums to ensure proper tag handling
935+ let resp = await env . BUCKET . put ( 'multipleChecksums ' , body , {
898936 md5 : md5Buffer ,
899937 } ) ;
900938 assert . ok ( resp ) ;
939+
940+ // Also test HEAD operation to verify checksum tags
941+ const headResp = await env . BUCKET . head ( 'multipleChecksums' ) ;
942+ assert . ok ( headResp ) ;
901943 }
902944 } ,
903945} ;
0 commit comments