<?php # fake a http request ini_set('display_errors', 1); error_reporting(E_ALL); $json = json_decode($_SERVER['argv'][1], true); $gwffile = $_SERVER['argv'][2]; foreach (array('_SERVER', '_GET', '_POST', '_REQUEST', '_COOKIE') as $k) { ${$k} = $json[$k]; } $_REQUEST_HEADER = $json['header']; global $_REQUEST_HEADER; $code = 0; try { ob_start(); require_once $gwffile; $output = ob_get_contents(); ob_end_clean(); } catch (Exception $e) { http_response_code(500); $output = htmlspecialchars($e); $code = 1; } $header = GWF_HTTPHeader::getResponseHeaders(); echo json_encode(array('header' => $header, 'output' => $output, 'status' => http_response_code())); die($code);
/** * set HTTP Response Header and return the content * */ public function response() { $status = $this->getStatus(); if ($status >= 300 && $status < 400) { # Redirection GWF_HTTPHeader::redirect($status, $this->getRedirect()); } else { GWF_HTTPHeader::statuscode($status); if ($status >= 200 && $status < 300) { # Success if (true === $this->get(self::$methods_allowed_to_cache, $this->METHOD)) { # TODO: set Modified Time and E-Tag } } } GWF_HTTPHeader::setHeaders($this->headers); # TODO: add GWF_Error return $this->getContent(); }
/** * Set HTTP status code * @param int $code */ public static function statuscode($code = NULL) { if (NULL !== $code) { self::$status = $code; } return http_response_code($code); }
public final function cacheControl() { if (false !== ($modified = GWF_HTTPHeader::getHeader('If-Modified-Since', false))) { if ($this->getModifiedTime() < $modified) { return GWF_Response(GWF_Response::NOT_MODIFIED); } } elseif (false !== ($etag = GWF_HTTPHeader::getHeader('E-Tag', false))) { if ($this->getETag() === $etag) { # TODO } } return false; }