Skip to content

Commit

Permalink
Check HTTP Method after mapRequestToAsset
Browse files Browse the repository at this point in the history
Closes #151
  • Loading branch information
oliverpool authored and GregBrimble committed Feb 8, 2024
1 parent 4f66a0e commit 02d6d07
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions packages/kv-asset-handler/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,11 +93,6 @@ const getAssetFromKV = async (event: FetchEvent, options?: Partial<Options>): Pr
throw new InternalError(`there is no KV namespace bound to the script`)
}

const SUPPORTED_METHODS = ['GET', 'HEAD']
if (!SUPPORTED_METHODS.includes(request.method)) {
throw new MethodNotAllowedError(`${request.method} is not a valid request method`)
}

const rawPathKey = new URL(request.url).pathname.replace(/^\/+/, '') // strip any preceding /'s
let pathIsEncoded = false
let requestKey
Expand All @@ -121,6 +116,11 @@ const getAssetFromKV = async (event: FetchEvent, options?: Partial<Options>): Pr
}
}

const SUPPORTED_METHODS = ['GET', 'HEAD']
if (!SUPPORTED_METHODS.includes(requestKey.method)) {
throw new MethodNotAllowedError(`${requestKey.method} is not a valid request method`)
}

const parsedUrl = new URL(requestKey.url)
const pathname = pathIsEncoded ? decodeURIComponent(parsedUrl.pathname) : parsedUrl.pathname // decode percentage encoded path only when necessary

Expand Down

0 comments on commit 02d6d07

Please sign in to comment.