Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions python_a2a/server/http.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,13 @@ def create_flask_app(agent: BaseA2AServer) -> Flask:
# Allow CORS for all routes
@app.after_request
def add_cors_headers(response):
response.headers['Access-Control-Allow-Origin'] = '*'
response.headers['Access-Control-Allow-Methods'] = 'GET, POST, OPTIONS'
response.headers['Access-Control-Allow-Headers'] = 'Content-Type, Authorization'
allowed_origins = os.environ.get("A2A_ALLOWED_ORIGINS", "").split(",")
origin = request.headers.get("Origin", "")
if origin and origin in allowed_origins:
response.headers['Access-Control-Allow-Origin'] = origin
response.headers['Access-Control-Allow-Methods'] = 'GET, POST, OPTIONS'
response.headers['Access-Control-Allow-Headers'] = 'Content-Type, Authorization'
response.headers['Vary'] = 'Origin'
return response

# Handle OPTIONS requests for CORS preflight
Expand Down