Skip to content

Bugs in x402-fetch #752

@juchiast

Description

@juchiast

We tried to use x402-fetch to send POST request and discovered some bugs:

  1. "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.

  1. Any custom headers will be discarded when you pass an already built Request to fetch

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
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions