Skip to content

Commit 8479aa6

Browse files
fix(client): send content-type header for requests with an omitted optional body
1 parent 51e1602 commit 8479aa6

1 file changed

Lines changed: 9 additions & 1 deletion

File tree

src/client.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1030,11 +1030,19 @@ export class ModernTreasury {
10301030
return () => controller.abort();
10311031
}
10321032

1033-
private buildBody({ options: { body, headers: rawHeaders } }: { options: FinalRequestOptions }): {
1033+
private buildBody({ options }: { options: FinalRequestOptions }): {
10341034
bodyHeaders: HeadersLike;
10351035
body: BodyInit | undefined;
10361036
} {
1037+
const { body, headers: rawHeaders } = options;
10371038
if (!body) {
1039+
// A resource method always passes a `body` key when its operation defines a
1040+
// request body, even if the caller omitted an optional body param. Keep the
1041+
// content-type for those, and only elide it for operations with no body at
1042+
// all (e.g. GET/DELETE).
1043+
if (body == null && 'body' in options) {
1044+
return this.#encoder({ body, headers: buildHeaders([rawHeaders]) });
1045+
}
10381046
return { bodyHeaders: undefined, body: undefined };
10391047
}
10401048
const headers = buildHeaders([rawHeaders]);

0 commit comments

Comments
 (0)