Skip to content

Commit

Permalink
feat: add version header
Browse files Browse the repository at this point in the history
  • Loading branch information
Alan Shaw committed Oct 19, 2022
1 parent 979b13b commit fcbf1ac
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
4 changes: 3 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ import {
withCarCids,
withUnsupportedFeaturesHandler,
withMemoryBudget,
withResponseMemoryRelease
withResponseMemoryRelease,
withVersionHeader
} from './middleware.js'

/**
Expand All @@ -36,6 +37,7 @@ export default {
const middleware = composeMiddleware(
withCdnCache,
withCorsHeaders,
withVersionHeader,
withContentDispositionHeader,
withErrorHandler,
withUnsupportedFeaturesHandler,
Expand Down
13 changes: 11 additions & 2 deletions src/middleware.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -144,3 +142,14 @@ export function withDagula (handler) {
return handler(request, env, { ...ctx, dagula })
}
}

/**
* @type {import('@web3-storage/gateway-lib').Middleware<import('@web3-storage/gateway-lib').Context>}
*/
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
}
}

0 comments on commit fcbf1ac

Please sign in to comment.