Skip to content

Commit 8716a27

Browse files
fix(client): send content-type header for requests with an omitted optional body
1 parent 83ea993 commit 8716a27

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
@@ -748,11 +748,19 @@ export class Unlayer {
748748
return () => controller.abort();
749749
}
750750

751-
private buildBody({ options: { body, headers: rawHeaders } }: { options: FinalRequestOptions }): {
751+
private buildBody({ options }: { options: FinalRequestOptions }): {
752752
bodyHeaders: HeadersLike;
753753
body: BodyInit | undefined;
754754
} {
755+
const { body, headers: rawHeaders } = options;
755756
if (!body) {
757+
// A resource method always passes a `body` key when its operation defines a
758+
// request body, even if the caller omitted an optional body param. Keep the
759+
// content-type for those, and only elide it for operations with no body at
760+
// all (e.g. GET/DELETE).
761+
if (body == null && 'body' in options) {
762+
return this.#encoder({ body, headers: buildHeaders([rawHeaders]) });
763+
}
756764
return { bodyHeaders: undefined, body: undefined };
757765
}
758766
const headers = buildHeaders([rawHeaders]);

0 commit comments

Comments
 (0)