Skip to content

Commit

Permalink
Merge pull request #24 from vemonet/fix-fetch-get
Browse files Browse the repository at this point in the history
Fix Content-Type header for `fetch` GET request
  • Loading branch information
ludovicm67 authored Nov 26, 2024
2 parents 8a5eab9 + c7ae45e commit c29a16a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/smooth-buckets-grab.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@zazuko/yasqe": patch
---

Fix `Content-Type` header for `fetch` GET request
5 changes: 4 additions & 1 deletion packages/yasqe/src/sparql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,16 +57,19 @@ export async function executeQuery(yasqe: Yasqe, config?: YasqeAjaxConfig): Prom
return; // Nothing to query
}
const abortController = new AbortController();

const fetchOptions: RequestInit = {
method: populatedConfig.reqMethod,
headers: {
Accept: populatedConfig.accept,
...(populatedConfig.headers || {}),
"Content-Type": populatedConfig.reqMethod === "POST" ? "application/x-www-form-urlencoded" : "",
},
credentials: populatedConfig.withCredentials ? "include" : "same-origin",
signal: abortController.signal,
};
if (fetchOptions?.headers && populatedConfig.reqMethod === "POST") {
(fetchOptions.headers as Record<string, string>)["Content-Type"] = "application/x-www-form-urlencoded";
}
const searchParams = new URLSearchParams();
for (const key in populatedConfig.args) {
const value = populatedConfig.args[key];
Expand Down

0 comments on commit c29a16a

Please sign in to comment.