Athlon1600 / php-proxy

A web proxy script written in PHP and built as an alternative to Glype.
https://www.php-proxy.com
MIT License
298 stars 158 forks source link

Some images give 404 not found #66

Closed khavishbhundoo closed 7 years ago

khavishbhundoo commented 7 years ago

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

khavishbhundoo commented 7 years ago

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" }

khavishbhundoo commented 7 years ago

This whole function could be replaced by

parse_str($query, $result);

There is no need to reinvent the wheel