-
Notifications
You must be signed in to change notification settings - Fork 1k
Closed
Description
We tried to use x402-fetch to send POST request and discovered some bugs:
- "request body is already used" error when sending the request a second time
When you call
| const response = await fetch(input, init); |
the fetch function consume the body, therefore when you call the request again, the body is already gone, leading to the error.
- Any custom headers will be discarded when you pass an already built
Requestto fetch
x402/typescript/packages/x402-fetch/src/index.ts
Lines 106 to 110 in 0761c76
| headers: { | |
| ...(init?.headers || {}), | |
| "X-PAYMENT": paymentHeader, | |
| "Access-Control-Expose-Headers": "X-PAYMENT-RESPONSE", | |
| }, |
These headers will replace the headers of input, not extend it, so if someone use:
fetch(new Request("http://example.com", {
// custom headers
}));The headers will be gone in the second request.
We've published a fixed version of the library at https://jsr.io/@space-operator/x402-fetch and will open a PR here.
Metadata
Metadata
Assignees
Labels
No labels