code = $code; $this->payload = $payload; $this->type = $type; $this->fields = $extraFields; } public function output() { if (!headers_sent()) { foreach ($this->fields as $field) { header($field); } $body = ""; if (!is_null($this->payload)) { switch ($this->type) { case self::T_JSON: $body = (string) json_encode($this->payload, \JSON_PRETTY_PRINT); break; default: $body = (string) $this->payload; break; } } if (strlen($body)) { header("Content-Type: ".$this->type); header("Content-Length: ".strlen($body)); } elseif ($this->code==200) { $this->code = 204; } try { $statusText = Arsse::$lang->msg("HTTP.Status.".$this->code); } catch (\JKingWeb\Arsse\Lang\Exception $e) { $statusText = ""; } header("Status: ".$this->code." ".$statusText); if (!$this->head) { echo $body; } } else { throw new REST\Exception("headersSent"); } } }