mirror of
https://github.com/versia-pub/api.git
synced 2025-12-06 08:28:19 +01:00
fix: 🐛 Fix bug setting all requests to have an empty body
This commit is contained in:
parent
6560c88b78
commit
d117cc9455
|
|
@ -180,5 +180,20 @@ describe("SignatureConstructor", () => {
|
|||
);
|
||||
expect(parts[3].split("=")[1]).toBeString();
|
||||
});
|
||||
|
||||
test("should correctly sign a Request", async () => {
|
||||
const url = new URL("https://example.com");
|
||||
const request = new Request(url.toString(), {
|
||||
method: "GET",
|
||||
body: body,
|
||||
});
|
||||
const newRequest = await ctor.sign(request);
|
||||
|
||||
headers = newRequest.headers;
|
||||
expect(headers.get("Signature")).toBeDefined();
|
||||
expect(headers.get("Date")).toBeDefined();
|
||||
|
||||
expect(await newRequest.text()).toBe(body);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
|||
|
|
@ -266,6 +266,8 @@ export class SignatureConstructor {
|
|||
headers: Headers = new Headers(),
|
||||
): Promise<Request | Headers> {
|
||||
if (requestOrMethod instanceof Request) {
|
||||
const request = requestOrMethod.clone();
|
||||
|
||||
const headers = await this.sign(
|
||||
requestOrMethod.method as HttpVerb,
|
||||
new URL(requestOrMethod.url),
|
||||
|
|
@ -273,8 +275,6 @@ export class SignatureConstructor {
|
|||
requestOrMethod.headers,
|
||||
);
|
||||
|
||||
const request = requestOrMethod.clone();
|
||||
|
||||
request.headers.set("Date", headers.get("Date") ?? "");
|
||||
request.headers.set("Signature", headers.get("Signature") ?? "");
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue