jenssegers / php-proxy

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

Problems with POST and forms #62

Open TobiasMorell opened 5 years ago

TobiasMorell commented 5 years ago

I'm trying to use this proxy to forward requests to an ASP.NET server on another domain. When I send a login request (POST to /api/login, request body containing a form) directly to the ASP.NET server it works fine, but when it has passed through the proxy I get an exception:

System.IO.IOException: Unexpected end of Stream, the content may have already been read by another component.

This exception occurs when I attempt to read the form from the request body.

I'm running the proxy with the default setup as provided in the readme file. Do I need to do something special to have the proxy include the forms in the proxied requests?

mohrajab commented 5 years ago

same thing here on two laravel projects with POST requests, any recommendation ??

TobiasMorell commented 5 years ago

I ended up giving up, so sadly no recommendations from my side.

ivantcholakov commented 5 years ago

Maybe this old piece of code would give an idea. https://github.com/gentics/proxy-php/commit/d825be13e4705616c2000b8f97a4237defbdb9b9

idontusenumbers commented 3 years ago

It seems to be related to chunked transfer encoding.

My caddy reverse proxy server gets this error:

{"level":"error","ts":1618986004.5862067,"logger":"http.handlers.reverse_proxy","msg":"reading from backend","error":"invalid byte in chunk length"}
{"level":"error","ts":1618986004.5862992,"logger":"http.handlers.reverse_proxy","msg":"aborting with incomplete response","error":"invalid byte in chunk length"}

I've worked around it by just removing that transfer encoding header just before emiting and it seems to work alright:

// chunked transfer encoding is broken; try just removing the header
if ($response->getHeader('Transfer-Encoding')[0] ?? "" === "chunked") {
    $response = $response->withoutHeader('Transfer-Encoding');
}

(new Laminas\HttpHandlerRunner\Emitter\SapiEmitter)->emit($response);
die();