@cloudflare/vite-plugin 1.9.6 → 1.10.0

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.
@@ -6143,7 +6143,6 @@ var worker_default = {
6143
6143
  userWorkerAhead: config.invoke_user_worker_ahead_of_assets
6144
6144
  });
6145
6145
  }
6146
- const maybeSecondRequest = request.clone();
6147
6146
  const routeToUserWorker = async ({
6148
6147
  asset
6149
6148
  }) => {
@@ -6154,7 +6153,7 @@ var worker_default = {
6154
6153
  }
6155
6154
  if (eyeballConfig.limitedAssetsOnly) {
6156
6155
  analytics.setData({ userWorkerFreeTierLimiting: true });
6157
- return new Response(renderLimitedResponse(maybeSecondRequest), {
6156
+ return new Response(renderLimitedResponse(request), {
6158
6157
  status: 429,
6159
6158
  headers: {
6160
6159
  "Content-Type": "text/html"
@@ -6169,12 +6168,12 @@ var worker_default = {
6169
6168
  asset,
6170
6169
  dispatchType: "worker" /* WORKER */
6171
6170
  });
6172
- let shouldBlockNonImageResponse = false;
6171
+ let shouldCheckContentType = false;
6173
6172
  if (url.pathname.endsWith("/_next/image")) {
6174
6173
  const queryURLParam = url.searchParams.get("url");
6175
6174
  if (queryURLParam && !queryURLParam.startsWith("/")) {
6176
- if (maybeSecondRequest.method !== "GET" || maybeSecondRequest.headers.get("sec-fetch-dest") !== "image") {
6177
- shouldBlockNonImageResponse = true;
6175
+ if (request.method !== "GET" || request.headers.get("sec-fetch-dest") !== "image") {
6176
+ shouldCheckContentType = true;
6178
6177
  analytics.setData({ abuseMitigationURLHost: queryURLParam });
6179
6178
  }
6180
6179
  }
@@ -6182,18 +6181,15 @@ var worker_default = {
6182
6181
  analytics.setData({
6183
6182
  timeToDispatch: performance.now() - startTimeMs
6184
6183
  });
6185
- if (shouldBlockNonImageResponse) {
6186
- const resp = await env.USER_WORKER.fetch(maybeSecondRequest);
6187
- const contentType = resp.headers.get("content-type") || "";
6188
- const isImageOrPlainText = contentType.startsWith("image/") || // Matches "text/plain", "text/plain;charset=UTF-8"
6189
- contentType.split(";")[0] === "text/plain";
6190
- if (!isImageOrPlainText && resp.status !== 304) {
6184
+ if (shouldCheckContentType) {
6185
+ const response = await env.USER_WORKER.fetch(request);
6186
+ if (response.status !== 304 && shouldBlockContentType(response)) {
6191
6187
  analytics.setData({ abuseMitigationBlocked: true });
6192
6188
  return new Response("Blocked", { status: 403 });
6193
6189
  }
6194
- return resp;
6190
+ return response;
6195
6191
  }
6196
- return env.USER_WORKER.fetch(maybeSecondRequest);
6192
+ return env.USER_WORKER.fetch(request);
6197
6193
  });
6198
6194
  };
6199
6195
  const routeToAssets = async ({
@@ -6209,7 +6205,7 @@ var worker_default = {
6209
6205
  analytics.setData({
6210
6206
  timeToDispatch: performance.now() - startTimeMs
6211
6207
  });
6212
- return env.ASSET_WORKER.fetch(maybeSecondRequest);
6208
+ return env.ASSET_WORKER.fetch(request);
6213
6209
  });
6214
6210
  };
6215
6211
  if (config.static_routing) {
@@ -6247,7 +6243,12 @@ var worker_default = {
6247
6243
  if (config.invoke_user_worker_ahead_of_assets) {
6248
6244
  return await routeToUserWorker({ asset: "static_routing" });
6249
6245
  }
6250
- const assetsExist = await env.ASSET_WORKER.unstable_canFetch(request);
6246
+ const assetsExist = await env.ASSET_WORKER.unstable_canFetch(
6247
+ new Request(request.url, {
6248
+ headers: request.headers,
6249
+ method: request.method
6250
+ })
6251
+ );
6251
6252
  if (config.has_user_worker && !assetsExist) {
6252
6253
  return await routeToUserWorker({ asset: "none" });
6253
6254
  }
@@ -6268,6 +6269,16 @@ var worker_default = {
6268
6269
  }
6269
6270
  }
6270
6271
  };
6272
+ function shouldBlockContentType(response) {
6273
+ const contentType = response.headers.get("content-type");
6274
+ if (contentType === null) {
6275
+ return true;
6276
+ }
6277
+ if (contentType.includes(",")) {
6278
+ return true;
6279
+ }
6280
+ return !(contentType.startsWith("image/") || contentType.split(";")[0] === "text/plain");
6281
+ }
6271
6282
  export {
6272
6283
  worker_default as default
6273
6284
  };