diff --git a/api/cora/cora.php b/api/cora/cora.php index 0d9a91d..14b9a6e 100644 --- a/api/cora/cora.php +++ b/api/cora/cora.php @@ -587,24 +587,24 @@ final class cora { * @throws \Exception If this is not a batch request and the content type * was altered from application/json without a custom response. */ - // public function set_headers($headers, $custom_response = false) { - // if(isset($this->request['batch']) === true) { - // if($custom_response === true) { - // throw new \Exception('Batch API requests can not use a custom response.', 1015); - // } - // if($this->content_type_is_json($headers) === false) { - // throw new \Exception('Batch API requests must return JSON.', 1014); - // } - // } - // else { - // // Not a batch request - // if($custom_response === false && $this->content_type_is_json($headers) === false) { - // throw new \Exception('Non-custom responses must return JSON.', 1016); - // } - // } - // $this->headers = $headers; - // $this->custom_response = $custom_response; - // } + public function set_headers($headers, $custom_response = false) { + if(isset($this->request['batch']) === true) { + if($custom_response === true) { + throw new \Exception('Batch API requests can not use a custom response.', 1015); + } + if($this->content_type_is_json($headers) === false) { + throw new \Exception('Batch API requests must return JSON.', 1014); + } + } + else { + // Not a batch request + if($custom_response === false && $this->content_type_is_json($headers) === false) { + throw new \Exception('Non-custom responses must return JSON.', 1016); + } + } + $this->headers = $headers; + $this->custom_response = $custom_response; + } /** * Return whether or not the current output headers indicate that the diff --git a/api/runtime_thermostat.php b/api/runtime_thermostat.php index 4cdd3e6..fea9129 100755 --- a/api/runtime_thermostat.php +++ b/api/runtime_thermostat.php @@ -792,13 +792,13 @@ class runtime_thermostat extends cora\crud { } while ($chunk_end < $download_end); fclose($output); - header('Content-type: text/csv'); - header('Content-Length: ' . $bytes); - header('Content-Disposition: attachment; filename="Beestat Export - ' . $ecobee_thermostat['identifier'] . '.csv"'); - header('Pragma: no-cache'); - header('Expires: 0'); - - die(); + $this->cora->set_headers([ + 'Content-Type' => 'text/csv', + 'Content-Length' => $bytes, + 'Content-Disposition' => 'attachment; filename="Beestat Export - ' . $ecobee_thermostat['identifier'] . '.csv"', + 'Pragma' => 'no-cache', + 'Expires' => '0', + ], true); } /**