/**
  * Respond to the client with the given response object.
  *
  * @param Response $response
  *
  * @return string
  */
 public function respond(Response $response)
 {
     $content_type = 'application/json';
     $this->send_header('Content-Type', $content_type . '; charset=' . get_option('blog_charset'));
     $this->send_headers($response->get_headers());
     $this->set_status($response->get_status());
     $result = $this->response_to_data($response);
     $result = json_encode($result);
     $json_error_message = $this->get_json_last_error();
     if ($json_error_message) {
         $json_error_obj = new Response(array('success' => false, 'error' => array('code' => 500, 'message' => $json_error_message), 500));
         $result = $this->response_to_data($json_error_obj);
         $result = json_encode($result);
     }
     return $result;
 }