wrangler 2.16.0 → 2.18.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.
@@ -459,31 +459,35 @@ async function generateHandler({
459
459
  async function generateResponse() {
460
460
  const match = staticRedirectsMatcher() || generateRedirectsMatcher()({ request })[0];
461
461
  if (match) {
462
- const { status, to } = match;
463
- const destination = new URL(to, request.url);
464
- const location = destination.origin === new URL(request.url).origin ? `${destination.pathname}${destination.search || search}${destination.hash}` : `${destination.href}${destination.search ? "" : search}${destination.hash}`;
465
- switch (status) {
466
- case 301:
467
- return new MovedPermanentlyResponse(location, void 0, {
468
- preventLeadingDoubleSlash: false
469
- });
470
- case 303:
471
- return new SeeOtherResponse(location, void 0, {
472
- preventLeadingDoubleSlash: false
473
- });
474
- case 307:
475
- return new TemporaryRedirectResponse(location, void 0, {
476
- preventLeadingDoubleSlash: false
477
- });
478
- case 308:
479
- return new PermanentRedirectResponse(location, void 0, {
480
- preventLeadingDoubleSlash: false
481
- });
482
- case 302:
483
- default:
484
- return new FoundResponse(location, void 0, {
485
- preventLeadingDoubleSlash: false
486
- });
462
+ if (match.status === 200) {
463
+ pathname = new URL(match.to, request.url).pathname;
464
+ } else {
465
+ const { status, to } = match;
466
+ const destination = new URL(to, request.url);
467
+ const location = destination.origin === new URL(request.url).origin ? `${destination.pathname}${destination.search || search}${destination.hash}` : `${destination.href}${destination.search ? "" : search}${destination.hash}`;
468
+ switch (status) {
469
+ case 301:
470
+ return new MovedPermanentlyResponse(location, void 0, {
471
+ preventLeadingDoubleSlash: false
472
+ });
473
+ case 303:
474
+ return new SeeOtherResponse(location, void 0, {
475
+ preventLeadingDoubleSlash: false
476
+ });
477
+ case 307:
478
+ return new TemporaryRedirectResponse(location, void 0, {
479
+ preventLeadingDoubleSlash: false
480
+ });
481
+ case 308:
482
+ return new PermanentRedirectResponse(location, void 0, {
483
+ preventLeadingDoubleSlash: false
484
+ });
485
+ case 302:
486
+ default:
487
+ return new FoundResponse(location, void 0, {
488
+ preventLeadingDoubleSlash: false
489
+ });
490
+ }
487
491
  }
488
492
  }
489
493
  if (!request.method.match(/^(get|head)$/i)) {
@@ -5680,7 +5684,7 @@ import { join } from "node:path";
5680
5684
  var REDIRECTS_VERSION = 1;
5681
5685
  var HEADERS_VERSION = 2;
5682
5686
  var ANALYTICS_VERSION = 1;
5683
- var PERMITTED_STATUS_CODES = /* @__PURE__ */ new Set([301, 302, 303, 307, 308]);
5687
+ var PERMITTED_STATUS_CODES = /* @__PURE__ */ new Set([200, 301, 302, 303, 307, 308]);
5684
5688
  var HEADER_SEPARATOR = ":";
5685
5689
  var MAX_LINE_LENGTH = 2e3;
5686
5690
  var MAX_HEADER_RULES = 100;
@@ -5851,6 +5855,10 @@ var validateUrl = (token, onlyRelative = false, includeSearch = false, includeHa
5851
5855
  onlyRelative ? "URLs should begin with a forward-slash." : 'URLs should either be relative (e.g. begin with a forward-slash), or use HTTPS (e.g. begin with "https://").'
5852
5856
  ];
5853
5857
  };
5858
+ function urlHasHost(token) {
5859
+ const host = URL_REGEX.exec(token);
5860
+ return Boolean(host && host.groups && host.groups.host);
5861
+ }
5854
5862
 
5855
5863
  // ../pages-shared/metadata-generator/parseHeaders.ts
5856
5864
  var LINE_IS_PROBABLY_A_PATH = new RegExp(/^([^\s]+:\/\/|^\/)/);
@@ -6059,7 +6067,15 @@ function parseRedirects(input) {
6059
6067
  invalid.push({
6060
6068
  line,
6061
6069
  lineNumber: i + 1,
6062
- message: `Valid status codes are 301, 302 (default), 303, 307, or 308. Got ${str_status}.`
6070
+ message: `Valid status codes are 200, 301, 302 (default), 303, 307, or 308. Got ${str_status}.`
6071
+ });
6072
+ continue;
6073
+ }
6074
+ if (/\/\*?$/.test(from) && /\/index(.html)?$/.test(to) && !urlHasHost(to)) {
6075
+ invalid.push({
6076
+ line,
6077
+ lineNumber: i + 1,
6078
+ message: "Infinite loop detected in this rule and has been ignored. This will cause a redirect to strip `.html` or `/index` and end up triggering this rule again. Please fix or remove this rule to silence this warning."
6063
6079
  });
6064
6080
  continue;
6065
6081
  }
@@ -6072,6 +6088,16 @@ function parseRedirects(input) {
6072
6088
  continue;
6073
6089
  }
6074
6090
  seen_paths.add(from);
6091
+ if (status === 200) {
6092
+ if (urlHasHost(to)) {
6093
+ invalid.push({
6094
+ line,
6095
+ lineNumber: i + 1,
6096
+ message: `Proxy (200) redirects can only point to relative paths. Got ${to}`
6097
+ });
6098
+ continue;
6099
+ }
6100
+ }
6075
6101
  rules.push({ from, to, status, lineNumber: i + 1 });
6076
6102
  }
6077
6103
  return {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "wrangler",
3
- "version": "2.16.0",
3
+ "version": "2.18.0",
4
4
  "description": "Command-line interface for all things Cloudflare Workers",
5
5
  "keywords": [
6
6
  "wrangler",
@@ -32,7 +32,7 @@ describe("wrangler", () => {
32
32
  "wrangler
33
33
 
34
34
  Commands:
35
- wrangler docs [command] 📚 Open wrangler's docs in your browser
35
+ wrangler docs [command..] 📚 Open wrangler's docs in your browser
36
36
  wrangler init [name] 📥 Initialize a basic Worker project, including a wrangler.toml file
37
37
  wrangler generate [name] [template] ✨ Generate a new Worker project from an existing Worker template. See https://github.com/cloudflare/templates
38
38
  wrangler dev [script] 👂 Start a local server for developing your worker
@@ -85,7 +85,7 @@ describe("wrangler", () => {
85
85
  wrangler
86
86
 
87
87
  Commands:
88
- wrangler docs [command] 📚 Open wrangler's docs in your browser
88
+ wrangler docs [command..] 📚 Open wrangler's docs in your browser
89
89
  wrangler init [name] 📥 Initialize a basic Worker project, including a wrangler.toml file
90
90
  wrangler generate [name] [template] ✨ Generate a new Worker project from an existing Worker template. See https://github.com/cloudflare/templates
91
91
  wrangler dev [script] 👂 Start a local server for developing your worker
@@ -362,7 +362,7 @@ describe("wrangler", () => {
362
362
  "wrangler
363
363
 
364
364
  Commands:
365
- wrangler docs [command] 📚 Open wrangler's docs in your browser
365
+ wrangler docs [command..] 📚 Open wrangler's docs in your browser
366
366
  wrangler init [name] 📥 Initialize a basic Worker project, including a wrangler.toml file
367
367
  wrangler generate [name] [template] ✨ Generate a new Worker project from an existing Worker template. See https://github.com/cloudflare/templates
368
368
  wrangler dev [script] 👂 Start a local server for developing your worker