Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/server.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@ test('Reads and writes from the file system', async () => {
const entry = await blobs.getWithMetadata('simple-key')
expect(entry?.metadata).toEqual(metadata)

const entryMetadata = await blobs.getMetadata('simple-key')
expect(entryMetadata?.metadata).toEqual(metadata)

await blobs.delete('simple-key')
expect(await blobs.get('simple-key')).toBe(null)

Expand Down
33 changes: 33 additions & 0 deletions src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,35 @@ export class BlobsServer {
stream.pipe(res)
}

async head(req: http.IncomingMessage, res: http.ServerResponse) {
const url = new URL(req.url ?? '', this.address)
const { dataPath, key, metadataPath } = this.getLocalPaths(url)

if (!dataPath || !metadataPath || !key) {
return this.sendResponse(req, res, 400)
}

const headers: Record<string, string> = {}

try {
const rawData = await fs.readFile(metadataPath, 'utf8')
const metadata = JSON.parse(rawData)
const encodedMetadata = encodeMetadata(metadata)

if (encodedMetadata) {
headers[METADATA_HEADER_INTERNAL] = encodedMetadata
}
} catch (error) {
this.logDebug('Could not read metadata file:', error)
}

for (const name in headers) {
res.setHeader(name, headers[name])
}

res.end()
}

async list(options: {
dataPath: string
metadataPath: string
Expand Down Expand Up @@ -257,6 +286,10 @@ export class BlobsServer {
case 'PUT':
return this.put(req, res)

case 'HEAD': {
return this.head(req, res)
}

default:
return this.sendResponse(req, res, 405)
}
Expand Down