php-proxy icon indicating copy to clipboard operation
php-proxy copied to clipboard

Problems with POST and forms

Open TobiasMorell opened this issue 6 years ago • 4 comments

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?

TobiasMorell avatar Feb 18 '19 21:02 TobiasMorell

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

mohrajab avatar Mar 13 '19 09:03 mohrajab

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

TobiasMorell avatar Mar 13 '19 17:03 TobiasMorell

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

ivantcholakov avatar Sep 01 '19 07:09 ivantcholakov

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();

idontusenumbers avatar Apr 21 '21 06:04 idontusenumbers