public function modify(HeaderCollectionInterface $responseHeader, RequestInterface $request)
 {
     $origin = $request->getHeaderCollection()->getHeaderValue(HeaderName::ORIGIN, '');
     if (!empty($origin)) {
         $responseHeader->setHeaderValue(HeaderName::ACCESS_CONTROL_ALLOW_ORIGIN, $origin);
     }
     $mustAllowCredentials = !empty($request->getHeaderCollection()->getHeaderValue(HeaderName::AUTHORIZATION, ''));
     if ($mustAllowCredentials) {
         $responseHeader->setHeaderValue(HeaderName::ACCESS_CONTROL_ALLOW_CREDENTIALS, 'true');
     }
 }
 public function writeResponse(ResponseInterface $response, RequestInterface $request)
 {
     //set default header-collection in case, exception was thrown while reading the request
     if (!$request->getHeaderCollection() instanceof HeaderCollectionInterface) {
         $request->setHeaderCollection(new HeaderCollection());
     }
     foreach ($this->responseHeaderModifier as $modifier) {
         $modifier->modify($response->getHeaderCollection(), $request);
     }
     $this->statusCodeWriter->writeResponseStatusCode($response->getStatusCode());
     $this->headerWriter->writeResponseHeader($response->getHeaderCollection());
     $content = $response->getContent();
     $requestedContentType = $request->getHeaderCollection()->getHeaderValue(HeaderName::ACCEPT, ContentType::APPLICATION_JSON);
     $this->contentWriter->writeResponseContent($content, $requestedContentType);
 }