Skip to content

Commit 7246bb9

Browse files
fix(client): send content-type header for requests with an omitted optional body
1 parent 41d0397 commit 7246bb9

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
@@ -687,11 +687,19 @@ export class SFCNodes {
687687
return () => controller.abort();
688688
}
689689

690-
private buildBody({ options: { body, headers: rawHeaders } }: { options: FinalRequestOptions }): {
690+
private buildBody({ options }: { options: FinalRequestOptions }): {
691691
bodyHeaders: HeadersLike;
692692
body: BodyInit | undefined;
693693
} {
694+
const { body, headers: rawHeaders } = options;
694695
if (!body) {
696+
// A resource method always passes a `body` key when its operation defines a
697+
// request body, even if the caller omitted an optional body param. Keep the
698+
// content-type for those, and only elide it for operations with no body at
699+
// all (e.g. GET/DELETE).
700+
if (body == null && 'body' in options) {
701+
return this.#encoder({ body, headers: buildHeaders([rawHeaders]) });
702+
}
695703
return { bodyHeaders: undefined, body: undefined };
696704
}
697705
const headers = buildHeaders([rawHeaders]);

0 commit comments

Comments
 (0)