Skip to content

Commit

Permalink
fix(foxy-nucleon): fix default content type
Browse files Browse the repository at this point in the history
  • Loading branch information
pheekus committed Jan 8, 2025
1 parent 89731d4 commit 2e7542c
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/elements/public/NucleonElement/API.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,14 @@ export class API extends CoreAPI<any> {
const request = typeof args[0] === 'string' ? new API.WHATWGRequest(...args) : args[0];

request.headers.set('FOXY-API-VERSION', '1');
if (!request.headers.has('Content-Type')) {
request.headers.set('Content-Type', 'application/json');

// WHATWGRequest adds text/plain content type by default.
// Our default is application/json so we need to override it.
if (['POST', 'PATCH', 'PUT'].includes(request.method)) {
const s = typeof args[0] === 'string' ? args[1]?.headers : args[0].headers;
if (new API.WHATWGHeaders(s).get('Content-Type') === null) {
request.headers.set('Content-Type', 'application/json');
}
}

const event = new FetchEvent('fetch', {
Expand Down

0 comments on commit 2e7542c

Please sign in to comment.