bref: Cannot read body content of POST request
v0.3
I try to retrieve the body content of a POST request with an HTTP application configuration
I use this simple handler :
# index.php
<?php
echo file_get_contents('php://input');
When testing my lambda via Api Gateway everything seems to work fine (when I manually specify the content-length) :
But with a « real » HTTP call I cannot read any content from the body of my request…
this issue come from this comment : https://github.com/mnapoli/bref/issues/116#issuecomment-453745811
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Comments: 20 (15 by maintainers)
Commits related to this issue
- Automatically set the Content-Length header on POST requests When a POST request is made without a Content-Length header the content of the request body is dropped by PHP-FPM. This auto-adds the hea... — committed to brefphp/bref by mnapoli 5 years ago
- Handle POST body with multibyte characters The Content-Length of the body is the number of bytes, not the number of characters. See https://mark.koli.ch/remember-kids-an-http-content-length-is-the-nu... — committed to brefphp/bref by mnapoli 5 years ago
@mnapoli Works like a charm. Thank you and also @timo-schaefer-sm
@Sh1d0w that’s now fixed thanks to @timo-schaefer-sm
Hello,
I came across the same issue, and could resolved it by forcing content length header on this file : https://github.com/mnapoli/bref/blob/0.3/src/Runtime/PhpFpm.php#L181-L183
PHP binary seems to ignore POST content if content-length header is not set, and this header is forced with this little piece of code. The tricky thing is : why content-length is not forwarded to lambda function ? I suspect a misconfiguration on API gateway stack which block forwarding this header.
@mnapoli perfect everything seems to work fine ! No worries I’m happy to help a little 😉
All that information is super helpful! FYI you can replace the
bootstrap
of the layer by creating abootstrap
file at the root of your project (and add debug stuff, e.g. byecho
ing stuff to stdout in the bootstrap).Here is Bref’s bootstrap for PHP-FPM: https://github.com/mnapoli/bref/blob/0.3/runtime/php/layers/fpm/bootstrap
@mnapoli FYI I have activated detailed logs to retrieve more information.
We can see that body is emptied during the “conversions” process.
Unfortunately Gateway logs are truncated before being sent to cloudwatch (https://forums.aws.amazon.com/thread.jspa?threadID=221740) and I think that we lost important information during the step :
Endpoint request body after transformations
Maybe you’ll find something interesting…