Skip to content

Commit 457c8cf

Browse files
committed
Add Connection: close header to A2A HTTP handler responses
Ensure each A2A discovery server response explicitly closes the connection to prevent keep-alive issues with the simple HTTPServer.
1 parent 4771932 commit 457c8cf

1 file changed

Lines changed: 5 additions & 0 deletions

File tree

teaagent/agentcard.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,12 +214,14 @@ def do_GET(self) -> None:
214214
if self.path == '/.well-known/agent.json':
215215
body = card_json.encode('utf-8')
216216
self.send_response(200)
217+
self.send_header('Connection', 'close')
217218
self.send_header('Content-Type', 'application/json')
218219
self.send_header('Content-Length', str(len(body)))
219220
self.end_headers()
220221
self.wfile.write(body)
221222
else:
222223
self.send_response(404)
224+
self.send_header('Connection', 'close')
223225
self.end_headers()
224226

225227
def do_POST(self) -> None:
@@ -233,19 +235,22 @@ def do_POST(self) -> None:
233235
)
234236
resp_body = json.dumps({'output': output}).encode('utf-8')
235237
self.send_response(200)
238+
self.send_header('Connection', 'close')
236239
self.send_header('Content-Type', 'application/json')
237240
self.send_header('Content-Length', str(len(resp_body)))
238241
self.end_headers()
239242
self.wfile.write(resp_body)
240243
except Exception as exc:
241244
resp_body = json.dumps({'error': str(exc)}).encode('utf-8')
242245
self.send_response(500)
246+
self.send_header('Connection', 'close')
243247
self.send_header('Content-Type', 'application/json')
244248
self.send_header('Content-Length', str(len(resp_body)))
245249
self.end_headers()
246250
self.wfile.write(resp_body)
247251
else:
248252
self.send_response(404)
253+
self.send_header('Connection', 'close')
249254
self.end_headers()
250255

251256
def log_message(self, *_: object) -> None:

0 commit comments

Comments
 (0)