@@ -134,6 +134,35 @@ export class BlobsServer {
134134 stream . pipe ( res )
135135 }
136136
137+ async head ( req : http . IncomingMessage , res : http . ServerResponse ) {
138+ const url = new URL ( req . url ?? '' , this . address )
139+ const { dataPath, key, metadataPath } = this . getLocalPaths ( url )
140+
141+ if ( ! dataPath || ! metadataPath || ! key ) {
142+ return this . sendResponse ( req , res , 400 )
143+ }
144+
145+ const headers : Record < string , string > = { }
146+
147+ try {
148+ const rawData = await fs . readFile ( metadataPath , 'utf8' )
149+ const metadata = JSON . parse ( rawData )
150+ const encodedMetadata = encodeMetadata ( metadata )
151+
152+ if ( encodedMetadata ) {
153+ headers [ METADATA_HEADER_INTERNAL ] = encodedMetadata
154+ }
155+ } catch ( error ) {
156+ this . logDebug ( 'Could not read metadata file:' , error )
157+ }
158+
159+ for ( const name in headers ) {
160+ res . setHeader ( name , headers [ name ] )
161+ }
162+
163+ res . end ( )
164+ }
165+
137166 async list ( options : {
138167 dataPath : string
139168 metadataPath : string
@@ -257,6 +286,10 @@ export class BlobsServer {
257286 case 'PUT' :
258287 return this . put ( req , res )
259288
289+ case 'HEAD' : {
290+ return this . head ( req , res )
291+ }
292+
260293 default :
261294 return this . sendResponse ( req , res , 405 )
262295 }
0 commit comments