Skip to content

Commit 84c75e7

Browse files
fix(client): send content-type header for requests with an omitted optional body
1 parent 6daaf27 commit 84c75e7

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
@@ -673,11 +673,19 @@ export class Fashn {
673673
return () => controller.abort();
674674
}
675675

676-
private buildBody({ options: { body, headers: rawHeaders } }: { options: FinalRequestOptions }): {
676+
private buildBody({ options }: { options: FinalRequestOptions }): {
677677
bodyHeaders: HeadersLike;
678678
body: BodyInit | undefined;
679679
} {
680+
const { body, headers: rawHeaders } = options;
680681
if (!body) {
682+
// A resource method always passes a `body` key when its operation defines a
683+
// request body, even if the caller omitted an optional body param. Keep the
684+
// content-type for those, and only elide it for operations with no body at
685+
// all (e.g. GET/DELETE).
686+
if (body == null && 'body' in options) {
687+
return this.#encoder({ body, headers: buildHeaders([rawHeaders]) });
688+
}
681689
return { bodyHeaders: undefined, body: undefined };
682690
}
683691
const headers = buildHeaders([rawHeaders]);

0 commit comments

Comments
 (0)