File tree Expand file tree Collapse file tree 2 files changed +20
-2
lines changed
examples/python/servers/fastapi
python/x402/src/x402/fastapi Expand file tree Collapse file tree 2 files changed +20
-2
lines changed Original file line number Diff line number Diff line change @@ -161,7 +161,9 @@ async def acp_budget(request: Request) -> Dict[str, Any]:
161161 Handle both GET and POST requests for ACP budget payment.
162162 x402scan may use either method depending on the request.
163163 """
164- return {
164+ from fastapi .responses import JSONResponse
165+
166+ response_data = {
165167 "message" : "pay acp job budget" ,
166168 "token" : "acp job payment token" ,
167169 "protocol" : "x402" ,
@@ -170,6 +172,15 @@ async def acp_budget(request: Request) -> Dict[str, Any]:
170172 "advice" : "not financial advice" ,
171173 "method" : request .method # Show which method was used
172174 }
175+
176+ # Explicitly disable compression for x402scan compatibility
177+ return JSONResponse (
178+ content = response_data ,
179+ headers = {
180+ "Content-Encoding" : "identity" , # Tell CloudFlare: no compression
181+ "Cache-Control" : "no-transform" , # Prevent any transformation
182+ }
183+ )
173184
174185
175186# @app.get("/premium/content")
Original file line number Diff line number Diff line change @@ -146,7 +146,11 @@ def x402_response(error: str):
146146 accepts = payment_requirements ,
147147 error = error ,
148148 ).model_dump (by_alias = True )
149- headers = {"Content-Type" : "application/json" }
149+ headers = {
150+ "Content-Type" : "application/json" ,
151+ "Content-Encoding" : "identity" , # Disable compression for x402scan
152+ "Cache-Control" : "no-transform" , # Prevent any transformation
153+ }
150154
151155 return JSONResponse (
152156 content = response_data ,
@@ -206,6 +210,9 @@ def x402_response(error: str):
206210 response .headers ["X-PAYMENT-RESPONSE" ] = base64 .b64encode (
207211 settle_response .model_dump_json (by_alias = True ).encode ("utf-8" )
208212 ).decode ("utf-8" )
213+ # Disable compression for x402scan compatibility
214+ response .headers ["Content-Encoding" ] = "identity"
215+ response .headers ["Cache-Control" ] = "no-transform"
209216 else :
210217 return x402_response (
211218 "Settle failed: "
You can’t perform that action at this time.
0 commit comments