php-http / curl-client

cURL client
http://httplug.io
MIT License
443 stars 28 forks source link

Content-Length header is misleading #35

Open igorsantos07 opened 6 years ago

igorsantos07 commented 6 years ago

I'm using the curl-client to run SOAP requests from Phpro/SoapClient. It includes a debug method that brings up request and response headers, so we can inspect what's going on. I also instantiated a PluginClient with a LoggerPlugin, just to be on the safe side. I'm debugging a supposedly missing Content-Length header my server is complaining about.

A request I'm running reports on those two types of logs the header Content-Length: 1150, while the body actually has 1596 chars. After a lot of digging around, I found that those loggers refer to headers inside the RequestInterface object, while the Content-Length header is silently changed inside Http\Client\Curl\Client::createHeaders() - but only passed as cURL options, and not upwards as well.

For the sanity of other developers, this value should also be changed on the request object. I'm not doing a PR as I don't even know if that object is supposed to be modified, or the best way to do it around here.

joelwurtz commented 6 years ago

That's not possible since a request object is immutable, so even if it's modified there is no way other class will know about this :/

mekras commented 6 years ago

I think we can calculate Content-length manually only if it was not already set in request.