From a7f76bba35a7d603961bfa6fb374472cb8e952c2 Mon Sep 17 00:00:00 2001 From: Rene Reimann Date: Tue, 8 Sep 2026 21:19:46 +0200 Subject: [PATCH] Fix: send Accept: application/json header on all requests (#157) --- src/Core/Transport/RequestHandler.php | 3 ++- test/Unit/Core/RequestHandlerTest.php | 20 ++++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/src/Core/Transport/RequestHandler.php b/src/Core/Transport/RequestHandler.php index bfe2d72..e84791b 100644 --- a/src/Core/Transport/RequestHandler.php +++ b/src/Core/Transport/RequestHandler.php @@ -217,7 +217,8 @@ private function dispatch(string $method, string $uri, array $options): Response $this->logger->debug("Zammad API request: {$method} {$fullUri}"); try { - $request = $this->requestFactory->createRequest($method, $fullUri); + $request = $this->requestFactory->createRequest($method, $fullUri) + ->withHeader('Accept', 'application/json'); if (isset($options['headers']) && is_array($options['headers'])) { foreach ($options['headers'] as $name => $value) { diff --git a/test/Unit/Core/RequestHandlerTest.php b/test/Unit/Core/RequestHandlerTest.php index ad9030a..94c1318 100644 --- a/test/Unit/Core/RequestHandlerTest.php +++ b/test/Unit/Core/RequestHandlerTest.php @@ -167,6 +167,26 @@ public function testGetLastResponseReturnsLastResponseAfterRequest(): void self::assertNotNull($this->handler->getLastResponse()); } + public function testRequestsSendAcceptJsonHeader(): void + { + $this->httpClient->response = new Response(200, [], '{}'); + + $this->handler->get('tickets'); + + self::assertNotNull($this->httpClient->lastRequest); + self::assertSame('application/json', $this->httpClient->lastRequest->getHeaderLine('Accept')); + } + + public function testRequestsSendAcceptJsonHeaderOnPost(): void + { + $this->httpClient->response = new Response(201, [], '{}'); + + $this->handler->post('tickets', ['title' => 'x']); + + self::assertNotNull($this->httpClient->lastRequest); + self::assertSame('application/json', $this->httpClient->lastRequest->getHeaderLine('Accept')); + } + public function testGetRawWithQueryParamsAppendsToUri(): void { $this->httpClient->response = new Response(200, [], 'binary');