Skip to content

Conversation

@jclerc
Copy link

@jclerc jclerc commented Oct 5, 2016

As resources may have a header like Content-Type: text/javascript;charset=UTF-8

jclerc and others added 2 commits October 5, 2016 12:49
As resources may have a header like `Content-Type: text/javascript;charset=UTF-8`
@jclerc
Copy link
Author

jclerc commented Oct 18, 2016

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.

@siverson101
Copy link

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.

@siverson101
Copy link

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);
}

@jclerc
Copy link
Author

jclerc commented Nov 8, 2016

Why?

My solution just works in few line and is very efficient as it is.

webaddicto added a commit to webaddicto/php-proxy that referenced this pull request Oct 27, 2017
Updated PR Athlon1600#37 by JClerc to have no conflicts with the base branch.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants