Skip to content

Commit 095eba1

Browse files
fix(client): send content-type header for requests with an omitted optional body
1 parent d11a496 commit 095eba1

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
@@ -1086,11 +1086,19 @@ export class Lithic {
10861086
return () => controller.abort();
10871087
}
10881088

1089-
private buildBody({ options: { body, headers: rawHeaders } }: { options: FinalRequestOptions }): {
1089+
private buildBody({ options }: { options: FinalRequestOptions }): {
10901090
bodyHeaders: HeadersLike;
10911091
body: BodyInit | undefined;
10921092
} {
1093+
const { body, headers: rawHeaders } = options;
10931094
if (!body) {
1095+
// A resource method always passes a `body` key when its operation defines a
1096+
// request body, even if the caller omitted an optional body param. Keep the
1097+
// content-type for those, and only elide it for operations with no body at
1098+
// all (e.g. GET/DELETE).
1099+
if (body == null && 'body' in options) {
1100+
return this.#encoder({ body, headers: buildHeaders([rawHeaders]) });
1101+
}
10941102
return { bodyHeaders: undefined, body: undefined };
10951103
}
10961104
const headers = buildHeaders([rawHeaders]);

0 commit comments

Comments
 (0)