/**
  * Will be invoked when login will be re-submitted.
  *
  * @param \AppserverIo\Psr\Servlet\Http\HttpServletRequestInterface  $servletRequest  The servlet request instance
  * @param \AppserverIo\Psr\Servlet\Http\HttpServletResponseInterface $servletResponse The servlet response instance
  *
  * @return void
  */
 protected function onResubmit(HttpServletRequestInterface $servletRequest, HttpServletResponseInterface $servletResponse)
 {
     // load the session from the request
     if ($session = $servletRequest->getSession()) {
         // restore the old request from the session
         $this->restoreRequest($servletRequest, $session);
     }
 }
 public function prepareResponse(HttpServletRequestInterface $servletRequest, HttpServletResponseInterface $servletResponse)
 {
     error_log("Now in " . __METHOD__ . " handling request " . $servletRequest->getUri());
     // load the session and persist the data from $_SESSION
     $session = $servletRequest->getSession();
     if ($session != null && isset($_SESSION)) {
         foreach ($_SESSION as $namespace => $data) {
             if ($namespace !== 'identifier') {
                 error_log("Now add data for session {$session->getId()} and namespace {$namespace}: " . PHP_EOL . var_export($data, true));
                 $session->putData($namespace, $data);
             }
         }
     }
     // add the status code we've caught from the legacy app
     $servletResponse->setStatusCode(appserver_get_http_response_code());
     // add this header to prevent .php request to be cached
     $servletResponse->addHeader(Protocol::HEADER_EXPIRES, '19 Nov 1981 08:52:00 GMT');
     $servletResponse->addHeader(Protocol::HEADER_CACHE_CONTROL, 'no-store, no-cache, must-revalidate, post-check=0, pre-check=0');
     $servletResponse->addHeader(Protocol::HEADER_PRAGMA, 'no-cache');
     // set per default text/html mimetype
     $servletResponse->addHeader(Protocol::HEADER_CONTENT_TYPE, 'text/html');
     error_log("============= RESPONSE before appserver_get_headers(true) =================");
     error_log(var_export($servletResponse, true));
     // grep headers and set to response object
     foreach (appserver_get_headers(true) as $i => $h) {
         // set headers defined in sapi headers
         $h = explode(':', $h, 2);
         if (isset($h[1])) {
             // load header key and value
             $key = trim($h[0]);
             $value = trim($h[1]);
             // if no status, add the header normally
             if ($key === Protocol::HEADER_STATUS) {
                 // set status by Status header value which is only used by fcgi sapi's normally
                 $servletResponse->setStatus($value);
             } elseif ($key === Protocol::HEADER_SET_COOKIE) {
                 $servletResponse->addHeader($key, $value, true);
             } else {
                 $servletResponse->addHeader($key, $value);
             }
         }
     }
     error_log("============= RESPONSE after appserver_get_headers(true) =================");
     error_log(var_export($servletResponse, true));
 }