miniflare 0.0.0-e4fe35cc5 → 0.0.0-e7ea6005c

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -10,7 +10,11 @@ var assets_kv_worker_default = {
10
10
  if (entry === void 0)
11
11
  return new Response("Not Found", { status: 404 });
12
12
  let { filePath, contentType } = entry, response = await env[SharedBindings.MAYBE_SERVICE_BLOBS].fetch(
13
- new URL(filePath, "http://placeholder")
13
+ new URL(
14
+ // somewhere in blobservice I think this is being decoded again
15
+ filePath.split("/").map((x) => encodeURIComponent(x)).join("/"),
16
+ "http://placeholder"
17
+ )
14
18
  ), newResponse = new Response(response.body, response);
15
19
  return newResponse.headers.append(
16
20
  "cf-kv-metadata",
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../../src/workers/assets/assets-kv.worker.ts"],
4
- "mappings": ";AAAA,SAAS,sBAAsB;AAW/B,IAAO,2BAA8B;AAAA,EACpC,MAAM,MAAM,SAAS,KAAK;AAEzB,QAAI,QAAQ,WAAW,OAAO;AAC7B,UAAM,UAAU,UAAU,QAAQ,OAAO,YAAY;AACrD,aAAO,IAAI,SAAS,SAAS,EAAE,QAAQ,KAAK,YAAY,QAAQ,CAAC;AAAA;AAGlE,QAAM,WAAW,IAAI,IAAI,QAAQ,GAAG,EAAE,SAAS,UAAU,CAAC,GACpD,QAAQ,IAAI,mBAAmB,QAAQ;AAC7C,QAAI,UAAU;AACb,aAAO,IAAI,SAAS,aAAa,EAAE,QAAQ,IAAI,CAAC;AAGjD,QAAM,EAAE,UAAU,YAAY,IAAI,OAE5B,WAAW,MADI,IAAI,eAAe,mBAAmB,EACvB;AAAA,MACnC,IAAI,IAAI,UAAU,oBAAoB;AAAA,IACvC,GACM,cAAc,IAAI,SAAS,SAAS,MAAM,QAAQ;AAExD,uBAAY,QAAQ;AAAA,MACnB;AAAA,MACA,oBAAoB;AAAA,IACrB,GACO;AAAA,EACR;AACD;",
4
+ "mappings": ";AAAA,SAAS,sBAAsB;AAW/B,IAAO,2BAA8B;AAAA,EACpC,MAAM,MAAM,SAAS,KAAK;AAEzB,QAAI,QAAQ,WAAW,OAAO;AAC7B,UAAM,UAAU,UAAU,QAAQ,OAAO,YAAY;AACrD,aAAO,IAAI,SAAS,SAAS,EAAE,QAAQ,KAAK,YAAY,QAAQ,CAAC;AAAA;AAGlE,QAAM,WAAW,IAAI,IAAI,QAAQ,GAAG,EAAE,SAAS,UAAU,CAAC,GACpD,QAAQ,IAAI,mBAAmB,QAAQ;AAC7C,QAAI,UAAU;AACb,aAAO,IAAI,SAAS,aAAa,EAAE,QAAQ,IAAI,CAAC;AAGjD,QAAM,EAAE,UAAU,YAAY,IAAI,OAE5B,WAAW,MADI,IAAI,eAAe,mBAAmB,EACvB;AAAA,MACnC,IAAI;AAAA;AAAA,QAEH,SACE,MAAM,GAAG,EACT,IAAI,CAAC,MAAM,mBAAmB,CAAC,CAAC,EAChC,KAAK,GAAG;AAAA,QACV;AAAA,MACD;AAAA,IACD,GACM,cAAc,IAAI,SAAS,SAAS,MAAM,QAAQ;AAExD,uBAAY,QAAQ;AAAA,MACnB;AAAA,MACA,oBAAoB;AAAA,IACrB,GACO;AAAA,EACR;AACD;",
5
5
  "names": []
6
6
  }
@@ -8789,14 +8789,15 @@ function isCacheable(request) {
8789
8789
 
8790
8790
  // ../workers-shared/asset-worker/src/handler.ts
8791
8791
  var handleRequest = async (request, configuration, exists, getByETag) => {
8792
- let { pathname, search } = new URL(request.url), intent = await getIntent(pathname, configuration, exists);
8792
+ let { pathname, search } = new URL(request.url), decodedPathname = decodePath(pathname), intent = await getIntent(decodedPathname, configuration, exists);
8793
8793
  if (!intent)
8794
8794
  return new NotFoundResponse();
8795
8795
  let method = request.method.toUpperCase();
8796
8796
  if (!["GET", "HEAD"].includes(method))
8797
8797
  return new MethodNotAllowedResponse();
8798
- if (intent.redirect)
8799
- return new TemporaryRedirectResponse(intent.redirect + search);
8798
+ let decodedDestination = intent.redirect ?? decodedPathname, encodedDestination = encodePath(decodedDestination);
8799
+ if (encodedDestination !== pathname || intent.redirect)
8800
+ return new TemporaryRedirectResponse(encodedDestination + search);
8800
8801
  if (!intent.asset)
8801
8802
  return new InternalServerErrorResponse(new Error("Unknown action"));
8802
8803
  let asset = await getByETag(intent.asset.eTag), headers = getHeaders(intent.asset.eTag, asset.contentType, request), strongETag = `"${intent.asset.eTag}"`, weakETag = `W/${strongETag}`, ifNoneMatch = request.headers.get("If-None-Match") || "";
@@ -8839,7 +8840,10 @@ var handleRequest = async (request, configuration, exists, getByETag) => {
8839
8840
  let redirectResult = null, eTagResult = null, exactETag = await exists(pathname);
8840
8841
  if (pathname.endsWith("/index")) {
8841
8842
  if (exactETag)
8842
- return { asset: { eTag: exactETag, status: 200 }, redirect: null };
8843
+ return {
8844
+ asset: { eTag: exactETag, status: 200 },
8845
+ redirect: null
8846
+ };
8843
8847
  if (redirectResult = await safeRedirect(
8844
8848
  `${pathname}.html`,
8845
8849
  pathname.slice(0, -5),
@@ -8875,7 +8879,10 @@ var handleRequest = async (request, configuration, exists, getByETag) => {
8875
8879
  return redirectResult;
8876
8880
  } else if (pathname.endsWith("/")) {
8877
8881
  if (eTagResult = await exists(`${pathname}index.html`))
8878
- return { asset: { eTag: eTagResult, status: 200 }, redirect: null };
8882
+ return {
8883
+ asset: { eTag: eTagResult, status: 200 },
8884
+ redirect: null
8885
+ };
8879
8886
  if (redirectResult = await safeRedirect(
8880
8887
  `${pathname.slice(0, -1)}.html`,
8881
8888
  pathname.slice(0, -1),
@@ -8902,7 +8909,13 @@ var handleRequest = async (request, configuration, exists, getByETag) => {
8902
8909
  ))
8903
8910
  return redirectResult;
8904
8911
  }
8905
- return exactETag ? { asset: { eTag: exactETag, status: 200 }, redirect: null } : (eTagResult = await exists(`${pathname}.html`)) ? { asset: { eTag: eTagResult, status: 200 }, redirect: null } : (redirectResult = await safeRedirect(
8912
+ return exactETag ? {
8913
+ asset: { eTag: exactETag, status: 200 },
8914
+ redirect: null
8915
+ } : (eTagResult = await exists(`${pathname}.html`)) ? {
8916
+ asset: { eTag: eTagResult, status: 200 },
8917
+ redirect: null
8918
+ } : (redirectResult = await safeRedirect(
8906
8919
  `${pathname}/index.html`,
8907
8920
  `${pathname}/`,
8908
8921
  configuration,
@@ -8913,7 +8926,10 @@ var handleRequest = async (request, configuration, exists, getByETag) => {
8913
8926
  let redirectResult = null, eTagResult = null, exactETag = await exists(pathname);
8914
8927
  if (pathname.endsWith("/index")) {
8915
8928
  if (exactETag)
8916
- return { asset: { eTag: exactETag, status: 200 }, redirect: null };
8929
+ return {
8930
+ asset: { eTag: exactETag, status: 200 },
8931
+ redirect: null
8932
+ };
8917
8933
  if (redirectResult = await safeRedirect(
8918
8934
  `${pathname}.html`,
8919
8935
  pathname.slice(0, -5),
@@ -8949,9 +8965,15 @@ var handleRequest = async (request, configuration, exists, getByETag) => {
8949
8965
  return redirectResult;
8950
8966
  } else if (pathname.endsWith("/")) {
8951
8967
  if (eTagResult = await exists(`${pathname}index.html`))
8952
- return { asset: { eTag: eTagResult, status: 200 }, redirect: null };
8968
+ return {
8969
+ asset: { eTag: eTagResult, status: 200 },
8970
+ redirect: null
8971
+ };
8953
8972
  if (eTagResult = await exists(`${pathname.slice(0, -1)}.html`))
8954
- return { asset: { eTag: eTagResult, status: 200 }, redirect: null };
8973
+ return {
8974
+ asset: { eTag: eTagResult, status: 200 },
8975
+ redirect: null
8976
+ };
8955
8977
  } else if (pathname.endsWith(".html")) {
8956
8978
  if (redirectResult = await safeRedirect(
8957
8979
  pathname,
@@ -8962,7 +8984,10 @@ var handleRequest = async (request, configuration, exists, getByETag) => {
8962
8984
  ))
8963
8985
  return redirectResult;
8964
8986
  if (exactETag)
8965
- return { asset: { eTag: exactETag, status: 200 }, redirect: null };
8987
+ return {
8988
+ asset: { eTag: exactETag, status: 200 },
8989
+ redirect: null
8990
+ };
8966
8991
  if (redirectResult = await safeRedirect(
8967
8992
  `${pathname.slice(0, -5)}/index.html`,
8968
8993
  `${pathname.slice(0, -5)}/`,
@@ -8972,7 +8997,10 @@ var handleRequest = async (request, configuration, exists, getByETag) => {
8972
8997
  ))
8973
8998
  return redirectResult;
8974
8999
  }
8975
- return exactETag ? { asset: { eTag: exactETag, status: 200 }, redirect: null } : (redirectResult = await safeRedirect(
9000
+ return exactETag ? {
9001
+ asset: { eTag: exactETag, status: 200 },
9002
+ redirect: null
9003
+ } : (redirectResult = await safeRedirect(
8976
9004
  `${pathname}.html`,
8977
9005
  `${pathname}/`,
8978
9006
  configuration,
@@ -8989,7 +9017,10 @@ var handleRequest = async (request, configuration, exists, getByETag) => {
8989
9017
  let redirectResult = null, eTagResult = null, exactETag = await exists(pathname);
8990
9018
  if (pathname.endsWith("/index")) {
8991
9019
  if (exactETag)
8992
- return { asset: { eTag: exactETag, status: 200 }, redirect: null };
9020
+ return {
9021
+ asset: { eTag: exactETag, status: 200 },
9022
+ redirect: null
9023
+ };
8993
9024
  if (pathname === "/index") {
8994
9025
  if (redirectResult = await safeRedirect(
8995
9026
  "/index.html",
@@ -9037,7 +9068,10 @@ var handleRequest = async (request, configuration, exists, getByETag) => {
9037
9068
  ))
9038
9069
  return redirectResult;
9039
9070
  if (exactETag)
9040
- return { asset: { eTag: exactETag, status: 200 }, redirect: null };
9071
+ return {
9072
+ asset: { eTag: exactETag, status: 200 },
9073
+ redirect: null
9074
+ };
9041
9075
  if (redirectResult = await safeRedirect(
9042
9076
  `${pathname.slice(0, -11)}.html`,
9043
9077
  pathname.slice(0, -11),
@@ -9050,7 +9084,10 @@ var handleRequest = async (request, configuration, exists, getByETag) => {
9050
9084
  else if (pathname.endsWith("/"))
9051
9085
  if (pathname === "/") {
9052
9086
  if (eTagResult = await exists("/index.html"))
9053
- return { asset: { eTag: eTagResult, status: 200 }, redirect: null };
9087
+ return {
9088
+ asset: { eTag: eTagResult, status: 200 },
9089
+ redirect: null
9090
+ };
9054
9091
  } else {
9055
9092
  if (redirectResult = await safeRedirect(
9056
9093
  `${pathname.slice(0, -1)}.html`,
@@ -9087,15 +9124,30 @@ var handleRequest = async (request, configuration, exists, getByETag) => {
9087
9124
  ))
9088
9125
  return redirectResult;
9089
9126
  }
9090
- return exactETag ? { asset: { eTag: exactETag, status: 200 }, redirect: null } : (eTagResult = await exists(`${pathname}.html`)) ? { asset: { eTag: eTagResult, status: 200 }, redirect: null } : (eTagResult = await exists(`${pathname}/index.html`)) ? { asset: { eTag: eTagResult, status: 200 }, redirect: null } : notFound(pathname, configuration, exists);
9127
+ return exactETag ? {
9128
+ asset: { eTag: exactETag, status: 200 },
9129
+ redirect: null
9130
+ } : (eTagResult = await exists(`${pathname}.html`)) ? {
9131
+ asset: { eTag: eTagResult, status: 200 },
9132
+ redirect: null
9133
+ } : (eTagResult = await exists(`${pathname}/index.html`)) ? {
9134
+ asset: { eTag: eTagResult, status: 200 },
9135
+ redirect: null
9136
+ } : notFound(pathname, configuration, exists);
9091
9137
  }, htmlHandlingNone = async (pathname, configuration, exists) => {
9092
9138
  let exactETag = await exists(pathname);
9093
- return exactETag ? { asset: { eTag: exactETag, status: 200 }, redirect: null } : notFound(pathname, configuration, exists);
9139
+ return exactETag ? {
9140
+ asset: { eTag: exactETag, status: 200 },
9141
+ redirect: null
9142
+ } : notFound(pathname, configuration, exists);
9094
9143
  }, notFound = async (pathname, configuration, exists) => {
9095
9144
  switch (configuration.not_found_handling) {
9096
9145
  case "single-page-application": {
9097
9146
  let eTag = await exists("/index.html");
9098
- return eTag ? { asset: { eTag, status: 200 }, redirect: null } : null;
9147
+ return eTag ? {
9148
+ asset: { eTag, status: 200 },
9149
+ redirect: null
9150
+ } : null;
9099
9151
  }
9100
9152
  case "404-page": {
9101
9153
  let cwd = pathname;
@@ -9103,7 +9155,10 @@ var handleRequest = async (request, configuration, exists, getByETag) => {
9103
9155
  cwd = cwd.slice(0, cwd.lastIndexOf("/"));
9104
9156
  let eTag = await exists(`${cwd}/404.html`);
9105
9157
  if (eTag)
9106
- return { asset: { eTag, status: 404 }, redirect: null };
9158
+ return {
9159
+ asset: { eTag, status: 404 },
9160
+ redirect: null
9161
+ };
9107
9162
  }
9108
9163
  return null;
9109
9164
  }
@@ -9123,7 +9178,7 @@ var handleRequest = async (request, configuration, exists, getByETag) => {
9123
9178
  };
9124
9179
  }
9125
9180
  return null;
9126
- };
9181
+ }, decodePath = (pathname) => pathname.split("/").map((x) => decodeURIComponent(x)).join("/"), encodePath = (pathname) => pathname.split("/").map((x) => encodeURIComponent(x)).join("/");
9127
9182
 
9128
9183
  // ../workers-shared/asset-worker/src/utils/kv.ts
9129
9184
  async function getAssetWithMetadataFromKV(assetsKVNamespace, assetKey, retries = 1) {
@@ -9169,8 +9224,8 @@ var src_default = class extends WorkerEntrypoint {
9169
9224
  }
9170
9225
  }
9171
9226
  async unstable_canFetch(request) {
9172
- let url = new URL(request.url), method = request.method.toUpperCase(), intent = await getIntent(
9173
- url.pathname,
9227
+ let url = new URL(request.url), method = request.method.toUpperCase(), decodedPathname = decodePath(url.pathname), intent = await getIntent(
9228
+ decodedPathname,
9174
9229
  {
9175
9230
  ...applyConfigurationDefaults(this.env.CONFIG),
9176
9231
  not_found_handling: "none"