Comments (3)
I'm not sure what you're asking for here. Can you show me the code you have now?
from php-proxy.
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.
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)
- How can I get a return HOT 1
- woot.com does not work on mobile phone screens
- How to allow to use file_get_contents() on proxified urls out of different proxy servers ? HOT 2
- Redirecting the complete URL inluding the request URI HOT 1
- Major problem on youtube HOT 1
- Some urls / domains get redirected HOT 2
- Proxify URL in data-popupurl tag HOT 1
- Plugin that forces Reddit to use the old design? HOT 2
- Block All Websites Except Some? HOT 1
- I have a paid feature development requirement, hope you can help me
- Can someone tell me what version of PHP this works on? HOT 1
- New Mod_security issue HOT 2
- Does not generate preview on Facebook HOT 7
- Missing descriptions of code statuses
- TAKE CARE (!!!), that script is VERY VERY DANGEROUS!!!!!!!!!!!!! HOT 3
- Exit php script execution if http response code is >=400 HOT 3
- Certain sites wont load HOT 3
- XMLHttpRequest is not proxified HOT 3
- CookiePlugin broken against google.com
- Web Telegram support
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from php-proxy.