jenssegers / php-proxy

A PHP proxy script with https and post support
https://jenssegers.com
932 stars 266 forks source link

Passes on path #60

Open czycha opened 5 years ago

czycha commented 5 years ago

Let's say I have this online at http://example.com/proxy and I'm using this to forward to http://api.com/api. When I make a JavaScript fetch request to http://example.com/proxy, the proxy ultimately requests http://api.com/api/proxy, resulting in a 404. Is there some sort of filtering that I should be doing to prevent this path from being appended?

I'm not doing much beyond the example in the readme.

czycha commented 5 years ago

I ended up filtering it, overriding the URI that the class passes in:

use GuzzleHttp\Psr7\Uri;

$proxy->filter(function ($request, $response, $next) use ($url) {
    $request = $request->withUri(new Uri($url));
    $response = $next($request, $response);
    return $response;
});

I still think that this is non-standard behavior—it should go to the URL provided by the to function and not modify it to this extent.