/**
  * Attempt to find a valid output view based on the value of the
  * HTTP_ACCEPT header.  Setting the configured POST variable will
  * cause the RESPONSE_TYPE header to be set to whatever you specify, while
  * returning a body containing the type you actually requested.
  */
 private function _detect_output_format()
 {
     // default output format
     $this->_format = $this->DEFAULT_FORMAT;
     $this->_view = self::$VALID_FORMAT_VIEWS[$this->_format];
     if (isset($_SERVER['HTTP_ACCEPT'])) {
         $accept_str = $_SERVER['HTTP_ACCEPT'];
         $http_accept = new HTTP_Accept($accept_str);
         // look for a supported format acceptable to the client
         foreach (self::$VALID_FORMAT_VIEWS as $format => $view) {
             // check if this format is in the client's HTTP_ACCEPT
             if ($http_accept->isMatchExact($format)) {
                 $this->_format = $format;
                 $this->_view = $view;
                 if (isset($_POST[self::$MISMATCH_VARNAME])) {
                     $this->_format = $_POST[self::$MISMATCH_VARNAME];
                 }
                 return;
             }
         }
         // check for an image-proxying url
         if (preg_match('/^image/', $_SERVER['HTTP_ACCEPT']) && $this->ctrlr && isset($this->ctrlr->image_proxies)) {
             foreach ($this->ctrlr->image_proxies as $name) {
                 if (preg_match("/{$name}\$/", $_SERVER['PHP_SELF'])) {
                     return;
                 }
             }
         }
         // many browsers, including iPhone and IE7, send a */* meaning they
         // are hopelessly promiscuous.  Just send default format.
         if (strpos($accept_str, '*/*') !== false) {
             return;
         }
         // not found!  Return a 415
         show_error("Unsupported request format. Valid: {$accept_str}", 415);
     }
 }
 /**
  * Based on a requested mime type, attempts to find a view which can
  * display that type.  Valid views are configured in config/formats.php.
  *
  * @param string  $req_format
  * @return string $view
  */
 protected function detect_view($req_format)
 {
     $http_accept = new HTTP_Accept($req_format);
     // look for a supported format acceptable to the client
     foreach (self::$VIEWS as $fmt => $vw) {
         // check if this format is in the client's HTTP_ACCEPT
         if ($http_accept->isMatchExact($fmt)) {
             $this->http_view = $vw;
             return $vw;
         }
     }
     // no view found - 415
     $accepts = implode(', ', array_keys(self::$VIEWS));
     header("Accept: {$accepts}");
     show_error("Unsupported request format: {$req_format}!", 415);
 }