Skip to content

Commit 2fe41cb

Browse files
fix(client): send content-type header for requests with an omitted optional body
1 parent 145b2ae commit 2fe41cb

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
@@ -709,11 +709,19 @@ export class CasParser {
709709
return () => controller.abort();
710710
}
711711

712-
private buildBody({ options: { body, headers: rawHeaders } }: { options: FinalRequestOptions }): {
712+
private buildBody({ options }: { options: FinalRequestOptions }): {
713713
bodyHeaders: HeadersLike;
714714
body: BodyInit | undefined;
715715
} {
716+
const { body, headers: rawHeaders } = options;
716717
if (!body) {
718+
// A resource method always passes a `body` key when its operation defines a
719+
// request body, even if the caller omitted an optional body param. Keep the
720+
// content-type for those, and only elide it for operations with no body at
721+
// all (e.g. GET/DELETE).
722+
if (body == null && 'body' in options) {
723+
return this.#encoder({ body, headers: buildHeaders([rawHeaders]) });
724+
}
717725
return { bodyHeaders: undefined, body: undefined };
718726
}
719727
const headers = buildHeaders([rawHeaders]);

0 commit comments

Comments
 (0)