public function negotiateRdfContentType($acceptHeader)
 {
     $contentTypes = array('application/rdf+xml', 'text/turtle', 'application/ld+json');
     $negotiationResults = array();
     $negotiatedType = http_negotiate_content_type($contentTypes, $negotiationResults);
     if (!empty($negotiationResults)) {
         return RdfType::getByMimeType($negotiatedType);
     }
     return null;
 }
Exemplo n.º 2
0
/**
 * Test Http functions.
 */
function test_functions()
{
    http_cache_last_modified();
    http_chunked_decode();
    http_deflate();
    http_inflate();
    http_build_cookie();
    http_date();
    http_get_request_body_stream();
    http_get_request_body();
    http_get_request_headers();
    http_match_etag();
    http_match_modified();
    http_match_request_header();
    http_support();
    http_negotiate_charset();
    http_negotiate_content_type();
    http_negotiate_language();
    ob_deflatehandler();
    ob_etaghandler();
    ob_inflatehandler();
    http_parse_cookie();
    http_parse_headers();
    http_parse_message();
    http_parse_params();
    http_persistent_handles_clean();
    http_persistent_handles_count();
    http_persistent_handles_ident();
    http_get();
    http_head();
    http_post_data();
    http_post_fields();
    http_put_data();
    http_put_file();
    http_put_stream();
    http_request_body_encode();
    http_request_method_exists();
    http_request_method_name();
    http_request_method_register();
    http_request_method_unregister();
    http_request();
    http_redirect();
    http_send_content_disposition();
    http_send_content_type();
    http_send_data();
    http_send_file();
    http_send_last_modified();
    http_send_status();
    http_send_stream();
    http_throttle();
    http_build_str();
    http_build_url();
}
 /**
  * utility function to replace http_negotiate_content_type when its not available
  * see: http://pecl.php.net/pecl_http
  **/
 private function negotiateContentType($request)
 {
     if (function_exists('http_negotiate_content_type')) {
         return http_negotiate_content_type(array_keys($this->responseTypes));
     }
     $string = $request->getHeader('Accept');
     $mimeTypes = array();
     // Accept header is case insensitive, and whitespace isn't important
     $string = strtolower(str_replace(' ', '', $string));
     // divide it into parts in the place of a ","
     $types = explode(',', $string);
     foreach ($types as $type) {
         // the default quality is 1.
         $quality = 1;
         // check if there is a different quality
         if (strpos($type, ';q=')) {
             // divide "mime/type;q=X" into two parts: "mime/type" / "X"
             list($type, $quality) = explode(';q=', $type);
         } elseif (strpos($type, ';')) {
             list($type, ) = explode(';', $type);
         }
         // WARNING: $q == 0 means, that mime-type isn't supported!
         if (array_key_exists($type, $this->responseTypes) and !array_key_exists($quality, $mimeTypes)) {
             $mimeTypes[$quality] = $type;
         }
     }
     // sort by quality descending
     arsort($mimeTypes);
     return current(array_values($mimeTypes));
 }
Exemplo n.º 4
0
 /**
  * Uses Request data to set some properties.
  * 
  * @param Request $request Current Request object.
  * @return $this
  */
 public function setRequest(Request $request)
 {
     // send body if not a HEAD request
     $this->send_body = !$request->is('HEAD');
     // first try to set content type using parameter (if set)
     if (!isset($request->content_type) || !$this->maybeSetContentType($request->content_type)) {
         // now try using header (if set)
         $this->content_type = http_negotiate_content_type(array_values($this->content_types));
     }
     // shall we gzip?
     if (http_in_request_header('accept-encoding', 'gzip') && extension_loaded('zlib')) {
         $this->gzip_body = true;
     }
     // For XHR/AJAX requests, don't cache response, nosniff, and deny iframes
     if ($request->isXhr()) {
         $this->setCacheHeaders(false);
         $this->nosniff();
         $this->denyIframes();
     }
     return $this;
 }