Open jclerc opened 7 years ago
Your commit will make it work as before. But the aim of this pull request is to ignore resources that have a charset at the end of their Content-Type
header, such as Content-Type: text/javascript;charset=UTF-8
.
So in_array
won't work, but strpos === 0
will.
What you want is use a startsWith check. Maybe add these to the helper class: function startsWith($haystack, $needle) { $length = strlen($needle); return (substr($haystack, 0, $length) === $needle); }
function endsWith($haystack, $needle) { $length = strlen($needle); if ($length == 0) { return true; }
return (substr($haystack, -$length) === $needle);
}
Then call if(startsWith($content_type, $type) ){
Or, split the string on ';' and only use the first part for the test.
You could also do: // Strip off ;charset=UTF-8 from Content-Type: text/javascript;charset=UTF-8 $pos = strpos($content_type, ';'); if ($pos !== false) { $content_type = substr($content_type, 0, $pos - 1); }
Why?
My solution just works in few line and is very efficient as it is.
As resources may have a header like
Content-Type: text/javascript;charset=UTF-8