public function respond($response = array(), $replaceResponse = false)
    {
        // Set any final data
        $this->set($response, $replaceResponse);

        // Make sure it only responds once
        if ($this->hasResponded()) {
            return;
        }

        // Clear anything that may have snuck in
        $this->cleanBuffer();

        if (self::$code == 204) {
            // No-body response
            $this->responseSent = true;
            return;
        }

        if (!empty($this->apiResponseCallback) && is_callable($this->apiResponseCallback)) {
            $callback = &$this->apiResponseCallback;
            $callback($this->response);
        }

        // Format for specific output type
        if ($this->responseFormat == 'JSON') {
            if ($this->jsonCallbackWrap) {
                echo $this->jsonCallbackWrap . '(';
            }

            echo json_encode($this->response);

            if ($this->jsonCallbackWrap) {
                echo ');';
            }
        } else {
            throw new \Exception('Invalid response format: '. $this->responseFormat);
        }

        // Indicate the response as already sent
        $this->responseSent = true;
    }