From 3d7370bc57d8e52def7c1fad64a8f334f1ae9c58 Mon Sep 17 00:00:00 2001 From: oliverpool <3864879+oliverpool@users.noreply.github.com> Date: Tue, 18 May 2021 08:57:20 +0200 Subject: [PATCH] Check HTTP Method after mapRequestToAsset Closes #151 --- packages/kv-asset-handler/src/index.ts | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/packages/kv-asset-handler/src/index.ts b/packages/kv-asset-handler/src/index.ts index 4ca62db5a8ad..c04762ad511e 100644 --- a/packages/kv-asset-handler/src/index.ts +++ b/packages/kv-asset-handler/src/index.ts @@ -93,11 +93,6 @@ const getAssetFromKV = async (event: FetchEvent, options?: Partial): 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 @@ -121,6 +116,11 @@ const getAssetFromKV = async (event: FetchEvent, options?: Partial): 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