diff --git a/lib/runtime/gateway_acp_client.dart b/lib/runtime/gateway_acp_client.dart index efd6c8a0..edd2f11c 100644 --- a/lib/runtime/gateway_acp_client.dart +++ b/lib/runtime/gateway_acp_client.dart @@ -566,7 +566,7 @@ class GatewayAcpClient { ); httpRequest.headers.set( HttpHeaders.acceptHeader, - 'text/event-stream, application/json', + _httpAcceptHeaderFor(endpoint, request.method), ); final authorization = await _resolveAuthorizationHeader( endpoint, @@ -1128,6 +1128,14 @@ bool _isOpenClawTaskSubmitMethod(String method) { return normalized == 'session.start' || normalized == 'session.message'; } +String _httpAcceptHeaderFor(Uri endpoint, String method) { + if (_isOpenClawTaskSubmitEndpoint(endpoint) && + _isOpenClawTaskSubmitMethod(method)) { + return 'application/json'; + } + return 'text/event-stream, application/json'; +} + class _GatewayAcpRpcRequest { const _GatewayAcpRpcRequest({ required this.id, diff --git a/test/runtime/gateway_acp_client_auth_test.dart b/test/runtime/gateway_acp_client_auth_test.dart index 0c467b0b..9ede68e7 100644 --- a/test/runtime/gateway_acp_client_auth_test.dart +++ b/test/runtime/gateway_acp_client_auth_test.dart @@ -244,6 +244,7 @@ void main() { ); expect(capture.authorizationHeader, 'Bearer bridge-token'); + expect(capture.acceptHeader, 'text/event-stream, application/json'); expect(capture.requestPath, '/acp/rpc'); expect((response['result'] as Map)['ok'], true); }); @@ -672,6 +673,7 @@ void main() { ); expect(capture.authorizationHeader, 'Bearer bridge-token'); + expect(capture.acceptHeader, 'application/json'); expect(capture.requestPath, '/gateway/openclaw'); expect(capture.requestPath, isNot(contains('/acp-server'))); expect(capture.requestPath, isNot(contains('/acp-server/gateway'))); @@ -715,6 +717,7 @@ void main() { onUpdate: (_) {}, ); + expect(capture.acceptHeader, 'application/json'); expect(capture.requestPath, '/gateway/openclaw'); expect(capture.requestBody, contains('"method":"session.message"')); }, @@ -1063,6 +1066,8 @@ Future<_CapturedAcpHttpServer> _startAcpHttpServer() async { server.listen((request) async { capture.authorizationHeader = request.headers.value(HttpHeaders.authorizationHeader) ?? ''; + capture.acceptHeader = + request.headers.value(HttpHeaders.acceptHeader) ?? ''; capture.requestPath = request.uri.path; final body = await utf8.decoder.bind(request).join(); capture.requestBody = body; @@ -1100,6 +1105,7 @@ class _CapturedAcpHttpServer { final HttpServer _server; final Uri baseEndpoint; String authorizationHeader = ''; + String acceptHeader = ''; String requestPath = ''; String requestBody = ''; final List requestBodies = [];