Athlon1600/php-proxy

Some images give 404 not found

Closed this issue · 2 comments

I use composer to install the proxy app and i tried to proxy this url
https://i.ytimg.com/vi/L7YrTk-Y0a0/hqdefault.jpg?sqp=-oaymwEWCMQBEG5IWvKriqkDCQgBFQAAiEIYAQ==&rs=AOn4CLCTNoPqAxat4TbMLLn0dSWb6jVrRA

I got 404 not found as an error so to dig deeper i added var_dump($options[CURLOPT_URL]); after line
$options[CURLOPT_URL] = $this->request->getUri();

https://i.ytimg.com/vi/L7YrTk-Y0a0/hqdefault.jpg?sqp=-oaymwEWCMQBEG5IWvKriqkDCQgBFQAAiEIYAQ&rs=AOn4CLCTNoPqAxat4TbMLLn0dSWb6jVrRA

Notice that Q== becomes Q

The bug lies in this function

// https://github.com/guzzle/psr7/blob/master/src/functions.php
	public static function parseQuery($query){
		
		$result = array();
		
		foreach(explode('&', $query) as $kvp){
			$parts = explode('=', $kvp);
			$key = rawurldecode($parts[0]);
			if(substr($key, -2) == '[]'){
				$key = substr($key, 0, -2);
            }
			
			// keys with NULL will be ignored in http_build_query - that's why it has to be ''
			$value = isset($parts[1]) ? rawurldecode($parts[1]) : '';
			
			// brand new key=value
			if(!isset($result[$key])){
				$result[$key] = $value;
			} else {
				// key already exists in some form...
				if(!is_array($result[$key])){
					$result[$key] = array($result[$key]);
				}
				
				$result[$key][] = $value;
			}
		}
		
		return $result;
	}

array(2) { ["sqp"]=> string(38) "-oaymwEWCMQBEG5IWvKriqkDCQgBFQAAiEIYAQ" ["rs"]=> string(34) "AOn4CLCTNoPqAxat4TbMLLn0dSWb6jVrRA" }

This whole function could be replaced by

parse_str($query, $result);

There is no need to reinvent the wheel