public function setRequestFormatByAcceptHeader(JoinPointInterface $joinPoint)
    {

        /** @var \Neos\Flow\Mvc\ActionRequest $actionRequest */
        $actionRequest = $joinPoint->getProxy();

        /**
         * The Accept header should be the only one to determine which resulting
         * data format the client is able to understand. But since some JS libs
         * do send Accept XML but Content-Type Json even when the expect to process
         * jsonapi.org format data we care about both, the Accept header as well
         * as the Content-Type header.
         */
        foreach (array('Accept', 'Http-Accept', 'Content-Type') as $fieldName) {
            $headerValue = $actionRequest->getHttpRequest()->getHeader($fieldName);
            foreach (array('application/json', 'application/vnd.api+json') as $acceptableValue) {
                if (strpos($headerValue, $acceptableValue) !== false) {
                    $actionRequest->setFormat('json');

                    return;
                }
            }
        }
    }