@@ -134,6 +134,35 @@ export class BlobsServer {
134
134
stream . pipe ( res )
135
135
}
136
136
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
+
137
166
async list ( options : {
138
167
dataPath : string
139
168
metadataPath : string
@@ -257,6 +286,10 @@ export class BlobsServer {
257
286
case 'PUT' :
258
287
return this . put ( req , res )
259
288
289
+ case 'HEAD' : {
290
+ return this . head ( req , res )
291
+ }
292
+
260
293
default :
261
294
return this . sendResponse ( req , res , 405 )
262
295
}
0 commit comments