Handle requests with a FormData payload (#17035)

This commit is contained in:
Jon Koops 2023-02-13 14:03:47 +01:00 committed by GitHub
parent 48a22ff2f3
commit 9d0bee9c59
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 3 deletions

View file

@ -209,6 +209,8 @@ export class Agent {
} else if (requestHeaders.get("content-type") === "text/plain") {
// Pass the payload as a plain string if the content type is 'text/plain'.
requestOptions.body = payload as unknown as string;
} else if (payload instanceof FormData) {
requestOptions.body = payload;
} else {
// Otherwise assume it's JSON and stringify it.
requestOptions.body = JSON.stringify(
@ -216,7 +218,7 @@ export class Agent {
);
}
if (!requestHeaders.has("content-type")) {
if (!requestHeaders.has("content-type") && !(payload instanceof FormData)) {
requestHeaders.set("content-type", "application/json");
}

View file

@ -979,7 +979,10 @@ export class Clients extends Resource<{ realm?: string }> {
},
});
public uploadKey = this.makeUpdateRequest<{ id: string; attr: string }, any>({
public uploadKey = this.makeUpdateRequest<
{ id: string; attr: string },
FormData
>({
method: "POST",
path: "/{id}/certificates/{attr}/upload",
urlParamKeys: ["id", "attr"],
@ -987,7 +990,7 @@ export class Clients extends Resource<{ realm?: string }> {
public uploadCertificate = this.makeUpdateRequest<
{ id: string; attr: string },
any
FormData
>({
method: "POST",
path: "/{id}/certificates/{attr}/upload-certificate",