Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Content-Length for POST when data empty #78

Open
wants to merge 1 commit into
base: 2.19.x
Choose a base branch
from

Conversation

rouja
Copy link

@rouja rouja commented Oct 3, 2023

Q A
Documentation no
Bugfix yes
BC Break no
New Feature no
RFC yes
QA no

Description

The RFC7230 says :

For example, a Content-Length header
field is normally sent in a POST request even when the value is 0
(indicating an empty payload body).

Some load balancers reject empty POST without a Content-Lenght set to 0 with an HTTP 411 error. For instance Google Global Load Balancers does.

@@ -1256,6 +1256,11 @@ protected function prepareHeaders($body, $uri)
$headers['Content-Length'] = strlen($body);
}
}
else {
if ($this->getMethod() == 'POST') {
$headers['Content-Length'] = 0;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about PUT, PATCH, etc.?

Also, this kind of change must be accompanied with a test.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi,

I'm not a developer but I can try to improve this PR. Do you have a procedure to run phpunit test locally ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey,

You can do this locally, if you have php and composer installed:

git clone <this-repo>
composer install
./vendor/bin/phpunit

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The contributing guidelines can also be helpful.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello,

I had a test.

For PUT, PATCH and others, I'm not sure what to do...

@rouja rouja force-pushed the fix-post-empty-content-length branch from 7c243d1 to d0d8e23 Compare October 3, 2023 17:58
@rouja rouja force-pushed the fix-post-empty-content-length branch 8 times, most recently from 6a8695e to 167f4cd Compare October 30, 2023 07:13
Signed-off-by: Jacques ROUSSEL <jacques.roussel@rouaje.com>
@rouja rouja force-pushed the fix-post-empty-content-length branch from 167f4cd to d16ce47 Compare October 30, 2023 07:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants