From c591267465f1535107afb121f5aa26ba4cac2274 Mon Sep 17 00:00:00 2001 From: Nick Pezza Date: Wed, 7 Feb 2024 12:07:54 -0500 Subject: [PATCH 1/3] Ensure fetch method is always uppercase --- src/http/fetch_request.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/http/fetch_request.js b/src/http/fetch_request.js index f4ff5adbe..f39fd8101 100644 --- a/src/http/fetch_request.js +++ b/src/http/fetch_request.js @@ -56,7 +56,7 @@ export class FetchRequest { this.fetchOptions = { credentials: "same-origin", redirect: "follow", - method: method, + method: method.toUpperCase(), headers: { ...this.defaultHeaders }, body: body, signal: this.abortSignal, @@ -79,7 +79,7 @@ export class FetchRequest { this.url = url this.fetchOptions.body = body - this.fetchOptions.method = fetchMethod + this.fetchOptions.method = fetchMethod.toUpperCase() } get headers() { From 64680d79f82cb0617bb8e46f80ad64b630132043 Mon Sep 17 00:00:00 2001 From: Nick Pezza Date: Wed, 7 Feb 2024 12:14:43 -0500 Subject: [PATCH 2/3] Fix tests --- src/tests/functional/form_submission_tests.js | 8 ++++---- src/tests/functional/visit_tests.js | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/tests/functional/form_submission_tests.js b/src/tests/functional/form_submission_tests.js index e7447944f..32d9366dd 100644 --- a/src/tests/functional/form_submission_tests.js +++ b/src/tests/functional/form_submission_tests.js @@ -188,7 +188,7 @@ test("supports transforming a POST submission to a GET in a turbo:submit-start l test("supports transforming a GET submission to a POST in a turbo:submit-start listener", async ({ page }) => { await page.evaluate(() => addEventListener("turbo:submit-start", (({ detail }) => { - detail.formSubmission.method = "post" + detail.formSubmission.method = "POST" detail.formSubmission.body.set("path", "/src/tests/fixtures/one.html") detail.formSubmission.body.set("greeting", "Hello, from an event listener") })) @@ -992,7 +992,7 @@ test("link method form submission submits a single request", async ({ page }) => const { fetchOptions } = await nextEventNamed(page, "turbo:before-fetch-request") assert.ok(await noNextEventNamed(page, "turbo:before-fetch-request")) - assert.equal(fetchOptions.method, "post", "[data-turbo-method] overrides the GET method") + assert.equal(fetchOptions.method, "POST", "[data-turbo-method] overrides the GET method") assert.equal(requestCounter, 1, "submits a single HTTP request") }) @@ -1006,7 +1006,7 @@ test("link method form submission inside frame submits a single request", async const { fetchOptions } = await nextEventNamed(page, "turbo:before-fetch-request") assert.ok(await noNextEventNamed(page, "turbo:before-fetch-request")) - assert.equal(fetchOptions.method, "post", "[data-turbo-method] overrides the GET method") + assert.equal(fetchOptions.method, "POST", "[data-turbo-method] overrides the GET method") assert.equal(requestCounter, 1, "submits a single HTTP request") }) @@ -1020,7 +1020,7 @@ test("link method form submission targeting frame submits a single request", asy const { fetchOptions } = await nextEventNamed(page, "turbo:before-fetch-request") assert.ok(await noNextEventNamed(page, "turbo:before-fetch-request")) - assert.equal(fetchOptions.method, "post", "[data-turbo-method] overrides the GET method") + assert.equal(fetchOptions.method, "POST", "[data-turbo-method] overrides the GET method") assert.equal(requestCounter, 2, "submits a single HTTP request then follows a redirect") }) diff --git a/src/tests/functional/visit_tests.js b/src/tests/functional/visit_tests.js index 782871747..dd0b97968 100644 --- a/src/tests/functional/visit_tests.js +++ b/src/tests/functional/visit_tests.js @@ -106,7 +106,7 @@ test("turbo:before-fetch-request event.detail", async ({ page }) => { await page.click("#same-origin-link") const { url, fetchOptions } = await nextEventNamed(page, "turbo:before-fetch-request") - assert.equal(fetchOptions.method, "get") + assert.equal(fetchOptions.method, "GET") assert.ok(url.includes("/src/tests/fixtures/one.html")) }) From b931708dd3890d40e09400e786c98df3d92eb32b Mon Sep 17 00:00:00 2001 From: Nick Pezza Date: Sat, 13 Jul 2024 11:13:45 -0400 Subject: [PATCH 3/3] Tweak setting fetchmethod --- src/observers/link_prefetch_observer.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/observers/link_prefetch_observer.js b/src/observers/link_prefetch_observer.js index 6265f075a..04c583ab1 100644 --- a/src/observers/link_prefetch_observer.js +++ b/src/observers/link_prefetch_observer.js @@ -93,7 +93,7 @@ export class LinkPrefetchObserver { } #tryToUsePrefetchedRequest = (event) => { - if (event.target.tagName !== "FORM" && event.detail.fetchOptions.method === "get") { + if (event.target.tagName !== "FORM" && event.detail.fetchOptions.method === "GET") { const cached = prefetchCache.get(event.detail.url.toString()) if (cached) {