Skip to content

Commit

Permalink
Merge pull request #1169 from npezza93/main
Browse files Browse the repository at this point in the history
Ensure fetch method is always uppercase
  • Loading branch information
brunoprietog authored Jul 13, 2024
2 parents a4f3a90 + b931708 commit 2a62bbf
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 8 deletions.
4 changes: 2 additions & 2 deletions src/http/fetch_request.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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() {
Expand Down
2 changes: 1 addition & 1 deletion src/observers/link_prefetch_observer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
8 changes: 4 additions & 4 deletions src/tests/functional/form_submission_tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}))
Expand Down Expand Up @@ -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")
})

Expand All @@ -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")
})

Expand All @@ -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")
})

Expand Down
2 changes: 1 addition & 1 deletion src/tests/functional/visit_tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
})

Expand Down

0 comments on commit 2a62bbf

Please sign in to comment.