Skip to content

Commit 2786b6c

Browse files
fix(client): send content-type header for requests with an omitted optional body
1 parent 6ca1066 commit 2786b6c

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
@@ -717,11 +717,19 @@ export class OzAPI {
717717
return () => controller.abort();
718718
}
719719

720-
private buildBody({ options: { body, headers: rawHeaders } }: { options: FinalRequestOptions }): {
720+
private buildBody({ options }: { options: FinalRequestOptions }): {
721721
bodyHeaders: HeadersLike;
722722
body: BodyInit | undefined;
723723
} {
724+
const { body, headers: rawHeaders } = options;
724725
if (!body) {
726+
// A resource method always passes a `body` key when its operation defines a
727+
// request body, even if the caller omitted an optional body param. Keep the
728+
// content-type for those, and only elide it for operations with no body at
729+
// all (e.g. GET/DELETE).
730+
if (body == null && 'body' in options) {
731+
return this.#encoder({ body, headers: buildHeaders([rawHeaders]) });
732+
}
725733
return { bodyHeaders: undefined, body: undefined };
726734
}
727735
const headers = buildHeaders([rawHeaders]);

0 commit comments

Comments
 (0)