From fcbf1ac4ac2d6d4ba4351d28007d97aca11909a1 Mon Sep 17 00:00:00 2001 From: Alan Shaw Date: Wed, 19 Oct 2022 18:01:17 +0100 Subject: [PATCH] feat: add version header --- src/index.js | 4 +++- src/middleware.js | 13 +++++++++++-- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/src/index.js b/src/index.js index bbe4c29..6d12a6e 100644 --- a/src/index.js +++ b/src/index.js @@ -19,7 +19,8 @@ import { withCarCids, withUnsupportedFeaturesHandler, withMemoryBudget, - withResponseMemoryRelease + withResponseMemoryRelease, + withVersionHeader } from './middleware.js' /** @@ -36,6 +37,7 @@ export default { const middleware = composeMiddleware( withCdnCache, withCorsHeaders, + withVersionHeader, withContentDispositionHeader, withErrorHandler, withUnsupportedFeaturesHandler, diff --git a/src/middleware.js b/src/middleware.js index 36e84a0..269be8c 100644 --- a/src/middleware.js +++ b/src/middleware.js @@ -98,8 +98,6 @@ export function withResponseMemoryRelease (handler) { const body = response.body if (!body) return response - console.log('adding response memory release transform...') - return new Response( body.pipeThrough(new TransformStream({ transform (chunk, controller) { @@ -144,3 +142,14 @@ export function withDagula (handler) { return handler(request, env, { ...ctx, dagula }) } } + +/** + * @type {import('@web3-storage/gateway-lib').Middleware} + */ +export function withVersionHeader (handler) { + return async (request, env, ctx) => { + const response = await handler(request, env, ctx) + response.headers.set('x-freeway-version', '1.3.0') + return response + } +}