Пример #1
0
 /**
  * Encodes the request using the configured encoding method, e. g. JSON.
  *
  * @param \AppserverIo\Psr\Servlet\Http\HttpServletRequestInterface  $servletRequest  The request instance
  * @param \AppserverIo\Psr\Servlet\Http\HttpServletResponseInterface $servletResponse The response instance
  *
  * @return void
  */
 public function encode(HttpServletRequestInterface $servletRequest, HttpServletResponseInterface $servletResponse)
 {
     // load the servlet response status code
     $statusCode = $servletResponse->getStatusCode();
     // load the result to be encoded, but only if we've NO redirect response (response code 300 - 399)
     if (($statusCode < 299 || $statusCode > 399) && ($result = $servletRequest->getAttribute(RequestKeys::RESULT))) {
         // encode the result with the configured encoder
         $viewData = $this->getEncodingHandler()->encode($result);
         // add the header for the content type and append the encoded content
         $servletResponse->addHeader(HttpProtocol::HEADER_CONTENT_TYPE, $viewData->getContentType());
         $servletResponse->appendBodyStream($viewData->getData());
     }
 }