3 // Copyright (c) 2016 Blue Static
5 // This program is free software: you can redistribute it and/or modify it
6 // under the terms of the GNU General Public License as published by the Free
7 // Software Foundation, either version 3 of the License, or any later version.
9 // This program is distributed in the hope that it will be useful, but WITHOUT
10 // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 // FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14 // You should have received a copy of the GNU General Public License along with
15 // this program. If not, see <http://www.gnu.org/licenses/>.
17 namespace hoplite\http2
;
19 require_once HOPLITE_ROOT
. '/http/response_code.php';
23 /*! @var integer The HTTP response code to return. */
26 /*! @var array A map of headers to values to be sent with the response. */
29 public function __construct($code=\hoplite\http\ResponseCode
::OK
) {
33 /*! @var string Raw HTTP response body. */
34 public function generate() {
35 http_response_code($this->code
);
36 foreach ($this->headers
as $header => $value) {
37 header("$header: $value");
42 class NotFoundResponse extends Response {
43 public function __construct() {
44 parent::__construct(\hoplite\http\ResponseCode::NOT_FOUND);
47 public function generate() {
49 print '<h1>404 - Not Found</h1>';
53 class TextResponse extends Response {
56 public function __construct($text) {
57 parent::__construct();
59 $this->headers['Content-Type'] = 'text/plain';
62 public function generate() {