x402
x402 copied to clipboard
intercept/buffer responses in flask middleware
Description
Flask middleware sends response to client immediately when route handler is called, if settlement fails resource was obtained for free.
This is solved similar as in the x402-express middleware by intercepting response methods, buffering all calls and replaying after successful settlement.
Tests
Tested with flask server example + forcing settle_response.success = False in the flask middleware.
Client output before:
{ report: { temperature: 70, weather: 'sunny' } }
Client output after:
{
x402Version: 1,
accepts: [
{
scheme: 'exact',
network: 'base-sepolia',
maxAmountRequired: '1000',
resource: 'http://localhost:4021/weather',
description: '',
mimeType: '',
outputSchema: [Object],
payTo: '0x1c47E9C085c2B7458F5b6C16cCBD65A65255a9f6',
maxTimeoutSeconds: 60,
asset: '0x036CbD53842c5426634e7929541eC2318f3dCF7e',
extra: [Object]
}
],
error: 'Settle failed: Unknown error'
}
Checklist
- [x] I have formatted and linted my code
- [x] All new and existing tests pass
- [x] My commits are signed (required for merge) -- you may need to rebase if you initially pushed unsigned commits
✅ Heimdall Review Status
| Requirement | Status | More Info | ||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Reviews |
✅
1/1
|
Denominator calculation
|
@phdargen is attempting to deploy a commit to the Coinbase Team on Vercel.
A member of the Team first needs to authorize it.