Wrong Content Typ from controller

Hello everybody,
I always get the content Typ text/html From Rest Client Tool
I try to create a controller for my API thanks for help
index.php

$app = new \Slim\App(['settings' => ['displayErrorDetails' => true]]);
$container = $app->getContainer();
$container[\src\Controller\Opticancore::class] = function ($container) {
    return new \src\Controller\Opticancore($container);
};
$app->get('/','\src\Controller\Opticancore:test');
    
$app->run();

Opticancore.php

use \Psr\Http\Message\ServerRequestInterface as Request;
use \Psr\Http\Message\ResponseInterface as Response;
class Opticancore {
 protected $ci;
    public function __construct($c) {
       $this->ci=$c;
    }
public function test(Request $request, Response $response){
$response->getBody()->write(json_encode(['YOUR_ARRAY']));
$response =  $response->withHeader(
   'Content-type',
   'application/json; charset=utf-8'
);
return $response;
}

Restclient Response
text/html; charset=UTF-8

Why can I not set the content typ to application/json; charset=utf-8’ in the controller for the Response?

Setting the response seems to work fine using your example:

$ curl localhost:8000 -v
* Rebuilt URL to: localhost:8000/
*   Trying 127.0.0.1...
* Connected to localhost (127.0.0.1) port 8000 (#0)
> GET / HTTP/1.1
> Host: localhost:8000
> User-Agent: curl/7.47.0
> Accept: */*
> 
< HTTP/1.1 200 OK
< Host: localhost:8000
< Connection: close
< X-Powered-By: PHP/7.0.4-7ubuntu2
< Content-type: application/json; charset=utf-8
< Content-Length: 14
< 
* Closing connection 0
["YOUR_ARRAY"]

What headers and response body are you seeing?

I use a rest client Tool
it shows me following predefined

I have test with other client tool but it shows the same

It looks like you have empty lines as part of your response. Because of these lines, the PHP interpreter may conclude that outputting has started and will ignore any new headers.

Check your source code if you have empty lines before the “<?php" tag. Also omit the "?>” closing tag to avoid unintented output of empty lines.

Yes right, after this closing tag i had empty lines. Thx for help llvdl.