Skip to content

Commit

Permalink
fix: add 501 error not implemented for range requests (#6)
Browse files Browse the repository at this point in the history
Tracking adding this in storacha/gateway-lib#12
  • Loading branch information
Alan Shaw authored Oct 17, 2022
1 parent 22f0baa commit c13f15c
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
handleBlock,
handleCar
} from '@web3-storage/gateway-lib/handlers'
import { withDagula, withCarCids } from './middleware.js'
import { withDagula, withCarCids, withUnsupportedFeaturesHandler } from './middleware.js'

/**
* @typedef {import('./bindings').Environment} Environment
Expand All @@ -29,6 +29,7 @@ export default {
withCorsHeaders,
withContentDispositionHeader,
withErrorHandler,
withUnsupportedFeaturesHandler,
withHttpGet,
withParsedIpfsUrl,
withCarCids,
Expand Down
16 changes: 16 additions & 0 deletions src/middleware.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,22 @@ const CAR_CODE = 0x0202
* @typedef {import('@web3-storage/gateway-lib').DagulaContext} DagulaContext
*/

/**
* Validates the request does not contain unsupported features.
* Returns 501 Not Implemented in case it has.
* @type {import('@web3-storage/gateway-lib').Middleware<import('@web3-storage/gateway-lib').Context>}
*/
export function withUnsupportedFeaturesHandler (handler) {
return (request, env, ctx) => {
// Range request https://github.com/web3-storage/gateway-lib/issues/12
if (request.headers.get('range')) {
throw new HttpError('Not Implemented', { status: 501 })
}

return handler(request, env, ctx)
}
}

/**
* Extracts CAR CIDs search params from the URL querystring or DUDEWHERE bucket.
* @type {import('@web3-storage/gateway-lib').Middleware<CarCidsContext & IpfsUrlContext, IpfsUrlContext, Environment>}
Expand Down

0 comments on commit c13f15c

Please sign in to comment.