Skip to content

Commit 2a62bbf

Browse files
authored
Merge pull request #1169 from npezza93/main
Ensure fetch method is always uppercase
2 parents a4f3a90 + b931708 commit 2a62bbf

File tree

4 files changed

+8
-8
lines changed

4 files changed

+8
-8
lines changed

src/http/fetch_request.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ export class FetchRequest {
5656
this.fetchOptions = {
5757
credentials: "same-origin",
5858
redirect: "follow",
59-
method: method,
59+
method: method.toUpperCase(),
6060
headers: { ...this.defaultHeaders },
6161
body: body,
6262
signal: this.abortSignal,
@@ -79,7 +79,7 @@ export class FetchRequest {
7979

8080
this.url = url
8181
this.fetchOptions.body = body
82-
this.fetchOptions.method = fetchMethod
82+
this.fetchOptions.method = fetchMethod.toUpperCase()
8383
}
8484

8585
get headers() {

src/observers/link_prefetch_observer.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ export class LinkPrefetchObserver {
9393
}
9494

9595
#tryToUsePrefetchedRequest = (event) => {
96-
if (event.target.tagName !== "FORM" && event.detail.fetchOptions.method === "get") {
96+
if (event.target.tagName !== "FORM" && event.detail.fetchOptions.method === "GET") {
9797
const cached = prefetchCache.get(event.detail.url.toString())
9898

9999
if (cached) {

src/tests/functional/form_submission_tests.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ test("supports transforming a POST submission to a GET in a turbo:submit-start l
188188
test("supports transforming a GET submission to a POST in a turbo:submit-start listener", async ({ page }) => {
189189
await page.evaluate(() =>
190190
addEventListener("turbo:submit-start", (({ detail }) => {
191-
detail.formSubmission.method = "post"
191+
detail.formSubmission.method = "POST"
192192
detail.formSubmission.body.set("path", "/src/tests/fixtures/one.html")
193193
detail.formSubmission.body.set("greeting", "Hello, from an event listener")
194194
}))
@@ -992,7 +992,7 @@ test("link method form submission submits a single request", async ({ page }) =>
992992
const { fetchOptions } = await nextEventNamed(page, "turbo:before-fetch-request")
993993

994994
assert.ok(await noNextEventNamed(page, "turbo:before-fetch-request"))
995-
assert.equal(fetchOptions.method, "post", "[data-turbo-method] overrides the GET method")
995+
assert.equal(fetchOptions.method, "POST", "[data-turbo-method] overrides the GET method")
996996
assert.equal(requestCounter, 1, "submits a single HTTP request")
997997
})
998998

@@ -1006,7 +1006,7 @@ test("link method form submission inside frame submits a single request", async
10061006
const { fetchOptions } = await nextEventNamed(page, "turbo:before-fetch-request")
10071007

10081008
assert.ok(await noNextEventNamed(page, "turbo:before-fetch-request"))
1009-
assert.equal(fetchOptions.method, "post", "[data-turbo-method] overrides the GET method")
1009+
assert.equal(fetchOptions.method, "POST", "[data-turbo-method] overrides the GET method")
10101010
assert.equal(requestCounter, 1, "submits a single HTTP request")
10111011
})
10121012

@@ -1020,7 +1020,7 @@ test("link method form submission targeting frame submits a single request", asy
10201020
const { fetchOptions } = await nextEventNamed(page, "turbo:before-fetch-request")
10211021

10221022
assert.ok(await noNextEventNamed(page, "turbo:before-fetch-request"))
1023-
assert.equal(fetchOptions.method, "post", "[data-turbo-method] overrides the GET method")
1023+
assert.equal(fetchOptions.method, "POST", "[data-turbo-method] overrides the GET method")
10241024
assert.equal(requestCounter, 2, "submits a single HTTP request then follows a redirect")
10251025
})
10261026

src/tests/functional/visit_tests.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ test("turbo:before-fetch-request event.detail", async ({ page }) => {
106106
await page.click("#same-origin-link")
107107
const { url, fetchOptions } = await nextEventNamed(page, "turbo:before-fetch-request")
108108

109-
assert.equal(fetchOptions.method, "get")
109+
assert.equal(fetchOptions.method, "GET")
110110
assert.ok(url.includes("/src/tests/fixtures/one.html"))
111111
})
112112

0 commit comments

Comments
 (0)