Git Product home page Git Product logo

Comments (3)

Athlon1600 avatar Athlon1600 commented on July 26, 2024

I'm not sure what you're asking for here. Can you show me the code you have now?

from php-proxy.

domsie avatar domsie commented on July 26, 2024

Hi, sorry for this :/
It is difficult for me to describe this behavior in english ;)
Here is the code [from HeaderRewritePlugin.php):

`
function onHeadersReceived(ProxyEvent $event){

    // so stupid... onCompleted won't be called on "streaming" responses
    $response = $event['response'];
    $request_url = $event['request']->getUri();

    $code = $response->getStatusCode();
    $text = $response->getStatusText();

    if($code >= 400 && $code <= 600){
        throw new \Exception("Error accessing resource: {$code} - {$text}");
    }

    // we need content-encoding (in case server refuses to serve it in plain text)
    $forward_headers = array('content-type', 'content-length', 'accept-ranges', 'content-range', 'content-disposition', 'location', 'set-cookie');

    foreach($response->headers->all() as $name => $value){

        // is this one of the headers we wish to forward back to the client?
        if(!in_array($name, $forward_headers)){
            $response->headers->remove($name);
        }
    }

//implement by me
$response->headers->set('Access-Control-Allow-Origin', '*');
$response->headers->set('Access-Control-Allow-Credentials', 'true');
$response->headers->set('Access-Control-Allow-Methods', 'GET, POST, OPTIONS');
$response->headers->set('Access-Control-Allow-Headers', 'DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type');

    if(!$response->headers->has('content-disposition')){

        $url_path = parse_url($request_url, PHP_URL_PATH);
        $filename = basename($url_path);

        $response->headers->set('content-disposition', 'filename="'.$filename.'"');
    }

 //implement by me
    if($response->headers->has('content-disposition')){

        .....
                    .....


        if ($inside == 1 || (string)$inside == "1" || $attachment == 1 || (string)$attachment == "1")
        {
                //File herunterladen
                $ch = curl_init();
                $user_agent = "Mozilla/4.0";
                curl_setopt ($ch, CURLOPT_URL, $request_url);
                curl_setopt ($ch, CURLOPT_USERAGENT, $user_agent);
                curl_setopt ($ch, CURLOPT_HEADER, 1);
                curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
                curl_setopt ($ch, CURLOPT_FOLLOWLOCATION, 0);
                curl_setopt ($ch, CURLOPT_TIMEOUT, 500);
                $content = curl_exec($ch);
                curl_close($ch); 
                $uniqid = uniqid();
                $filename = "/srv/www/htdocs/file_downloads/".$uniqid;
                $handle = fopen($filename, "w");
                fwrite($handle, $content);
                fclose($handle);
                //File herunterladen

                //Parameter base64 encoded übergeben
                $request_url_64 = base64_encode($request_url);
                $content_disposition_64 = base64_encode($content_disposition);
                $content_type_64 = base64_encode($content_type);

                $md_5 = md5_file($filename);

                $response->headers->set('location', 'https://..../safe_download.php?unique='.$uniqid.'&uri='.$request_url_64.'&cd='.$content_disposition_64.'&f='.$content_type_64.'&fs='.filesize($filename).' Byte&md5='.$md_5);

                //exit;
        }
        else
        {
            // proxify header location value
            if($response->headers->has('location')){

                $location = $response->headers->get('location');

                // just in case this is a relative url like: /en
                $response->headers->set('location', proxify_url($location, $request_url));
            }
        }

}
`

With
$response->headers->set('location', 'https://..../safe_download.php?unique='.$uniqid.'&uri='.$request_url_64.'&cd='.$content_disposition_64.'&f='.$content_type_64.'&fs='.filesize($filename).' Byte&md5='.$md_5);
i am want to make a redirect when the download-file match a special content-type; else i set the location with your part
`
// proxify header location value
if($response->headers->has('location')){

                $location = $response->headers->get('location');

                // just in case this is a relative url like: /en
                $response->headers->set('location', proxify_url($location, $request_url));
            }

`
....

when the header location change runs the first time (so when the file download runs the first time with this proxy) the redirect needs a loooooooot time; the second time it is better.
When i am put a exit; after the location change [ i thought that after the location change a few plugins still do a job and want to exit this and only call the redirect] i only become a blank site [no redirect or so].

from php-proxy.

Athlon1600 avatar Athlon1600 commented on July 26, 2024

I'm still not sure what you're trying to do here... and I think that there must be an easier way to do whatever you're trying to do. Why would you ever need to wait 60 seconds before downloading?

from php-proxy.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.