Skip to content
This repository was archived by the owner on Sep 8, 2021. It is now read-only.

Conversation

atrope
Copy link
Contributor

@atrope atrope commented Dec 3, 2018

Hi,
Testing in our environment we found a bug when sending the content-length Header via ALB.
The curl call stucks which i think it's a bug: https://stackoverflow.com/questions/9340734/php-curl-data-not-posted-if-headers-are-set

I Managed to fix by making the header on-the fly with the actual sent body.
For this i changed the order where we call the CURLOPT_HTTPHEADER to after the $body variable is defined.

@txase
Copy link
Member

txase commented Dec 3, 2018

While this does paper over the issue, it also is weirdly overriding specific behavior (setting the Content-Length header to a certain value).

I'd like to know more about why the Content-Length header is set incorrectly before overriding its value. Why is the built-in php webserver returning 0 for the response body length?

@atrope
Copy link
Contributor Author

atrope commented Dec 3, 2018

hey @txase I Think it is a PHP CURL known-bug...
As you can see the Stack Overflow link I sent here is from 2012 and it still happens..

@txase
Copy link
Member

txase commented Dec 4, 2018

The SO link says: If you want to send a request body, make sure to set the Content-Length header to the length of the body.

This change does something different. It overrides the Content-Length header value that is provided in the request. We can do that, but it's probably a sign that the client simply is making an invalid request.

Since this is coming through an ALB, can you get a dump of the request (including headers and body) sent to the ALB so we can verify whether it is setting the Content-Length header appropriately?

@atrope
Copy link
Contributor Author

atrope commented Dec 5, 2018

Hey @txase,
I AM also investigating here and trying another approach.
Here a dump of a the Events:


{
    "requestContext": {
        "elb": {
            "targetGroupArn": "arn:aws:elasticloadbalancing:us-east-1:272581579102:targetgroup/portal-sls/57c57ec773305a80"
        }
    },
    "httpMethod": "POST",
    "path": "/verificar/short",
    "multiValueQueryStringParameters": [],
    "multiValueHeaders": {
        "accept": [
            "*/*"
        ],
        "accept-encoding": [
            "gzip, deflate"
        ],
        "cache-control": [
            "no-cache"
        ],
        "connection": [
            "keep-alive"
        ],
        "content-length": [
            "169"
        ],
        "content-type": [
            "multipart/form-data; boundary=--------------------------490608822155697904763973"
        ],
        "cookie": [
            "SMSession=07f5d0d3a5f913bf2e8ccfe596606934"
        ],
        "host": [
            "sls.suamusica.com.br"
        ],
        "postman-token": [
            "ff36a950-4215-472a-af75-fbd1a0f079e5"
        ],
        "user-agent": [
            "PostmanRuntime/7.1.1"
        ],
        "x-amzn-trace-id": [
            "Root=1-5c07894f-e53a5ac0f74561e24599f662"
        ],
        "x-forwarded-for": [
            "213.57.219.40"
        ],
        "x-forwarded-port": [
            "443"
        ],
        "x-forwarded-proto": [
            "https"
        ]
    },
    "body": "LS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLTQ5MDYwODgyMjE1NTY5NzkwNDc2Mzk3Mw0KQ29udGVudC1EaXNwb3NpdGlvbjogZm9ybS1kYXRhOyBuYW1lPSJ1c2VybmFtZSINCg0KYXRyb3BlDQotLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tNDkwNjA4ODIyMTU1Njk3OTA0NzYzOTczLS0NCg==",
    "isBase64Encoded": true
}

{
    "resource": "/{proxy+}",
    "path": "/verificar/short",
    "httpMethod": "POST",
    "headers": {
        "Accept": "*/*",
        "Accept-Encoding": "gzip, deflate",
        "cache-control": "no-cache",
        "CloudFront-Forwarded-Proto": "https",
        "CloudFront-Is-Desktop-Viewer": "true",
        "CloudFront-Is-Mobile-Viewer": "false",
        "CloudFront-Is-SmartTV-Viewer": "false",
        "CloudFront-Is-Tablet-Viewer": "false",
        "CloudFront-Viewer-Country": "IL",
        "Content-Type": "multipart/form-data; boundary=--------------------------227495847972197776776649",
        "Host": "2taxm30w7g.execute-api.us-east-1.amazonaws.com",
        "Postman-Token": "a31df53e-32ef-4d10-9041-c619f9de8cdf",
        "User-Agent": "PostmanRuntime/7.1.1",
        "Via": "1.1 6e3453a91a5fc5982955003a408b061d.cloudfront.net (CloudFront)",
        "X-Amz-Cf-Id": "-CoK-i6IFc0oh_J9AN-3aZOUSh4VH6uj0Z7NTP7QRrLadOyGP2cPlQ==",
        "X-Amzn-Trace-Id": "Root=1-5c078961-5ebe587cacf42d94f18652a8",
        "X-Forwarded-For": "213.57.219.40, 70.132.15.83",
        "X-Forwarded-Port": "443",
        "X-Forwarded-Proto": "https"
    },
    "multiValueHeaders": {
        "Accept": [
            "*/*"
        ],
        "Accept-Encoding": [
            "gzip, deflate"
        ],
        "cache-control": [
            "no-cache"
        ],
        "CloudFront-Forwarded-Proto": [
            "https"
        ],
        "CloudFront-Is-Desktop-Viewer": [
            "true"
        ],
        "CloudFront-Is-Mobile-Viewer": [
            "false"
        ],
        "CloudFront-Is-SmartTV-Viewer": [
            "false"
        ],
        "CloudFront-Is-Tablet-Viewer": [
            "false"
        ],
        "CloudFront-Viewer-Country": [
            "IL"
        ],
        "Content-Type": [
            "multipart/form-data; boundary=--------------------------227495847972197776776649"
        ],
        "Host": [
            "2taxm30w7g.execute-api.us-east-1.amazonaws.com"
        ],
        "Postman-Token": [
            "a31df53e-32ef-4d10-9041-c619f9de8cdf"
        ],
        "User-Agent": [
            "PostmanRuntime/7.1.1"
        ],
        "Via": [
            "1.1 6e3453a91a5fc5982955003a408b061d.cloudfront.net (CloudFront)"
        ],
        "X-Amz-Cf-Id": [
            "-CoK-i6IFc0oh_J9AN-3aZOUSh4VH6uj0Z7NTP7QRrLadOyGP2cPlQ=="
        ],
        "X-Amzn-Trace-Id": [
            "Root=1-5c078961-5ebe587cacf42d94f18652a8"
        ],
        "X-Forwarded-For": [
            "213.57.219.40, 70.132.15.83"
        ],
        "X-Forwarded-Port": [
            "443"
        ],
        "X-Forwarded-Proto": [
            "https"
        ]
    },
    "queryStringParameters": null,
    "multiValueQueryStringParameters": null,
    "pathParameters": {
        "proxy": "verificar/short"
    },
    "stageVariables": null,
    "requestContext": {
        "resourceId": "s2dnay",
        "resourcePath": "/{proxy+}",
        "httpMethod": "POST",
        "extendedRequestId": "RbJnPGDcoAMFwfg=",
        "requestTime": "05/Dec/2018:08:16:33 +0000",
        "path": "/dev/verificar/short",
        "accountId": "272581579102",
        "protocol": "HTTP/1.1",
        "stage": "dev",
        "domainPrefix": "2taxm30w7g",
        "requestTimeEpoch": 1543997793514,
        "requestId": "13ab354d-f866-11e8-be40-dbd7ab2d94ee",
        "identity": {
            "cognitoIdentityPoolId": null,
            "accountId": null,
            "cognitoIdentityId": null,
            "caller": null,
            "sourceIp": "213.57.219.40",
            "accessKey": null,
            "cognitoAuthenticationType": null,
            "cognitoAuthenticationProvider": null,
            "userArn": null,
            "userAgent": "PostmanRuntime/7.1.1",
            "user": null
        },
        "domainName": "2taxm30w7g.execute-api.us-east-1.amazonaws.com",
        "apiId": "2taxm30w7g"
    },
    "body": "----------------------------227495847972197776776649\r\nContent-Disposition: form-data; name=\"username\"\r\n\r\natrope\r\n----------------------------227495847972197776776649--\r\n",
    "isBase64Encoded": false
}

@txase
Copy link
Member

txase commented Dec 5, 2018

The ALB event has the correct content-length value. The api gateway event is missing the content-length. I would expect the ALB request to work, but the api gateway request not to. But you're saying the ALB request is not working, while the api gateway is working?

@atrope
Copy link
Contributor Author

atrope commented Dec 6, 2018

@txase you are correct.. I Have no idea why, and i agree it should not be treated as "official" fix..
It does fix the issue, so in my layer i changed it.

I Will keep checking if we can solve this in another way.

Feel free to close the PR if you wish

@txase
Copy link
Member

txase commented Dec 6, 2018

That's very strange. I'm going to close this PR as there doesn't seem to be evidence that the layer itself is doing something wrong, but please re-open if you make any progress on the core issue!

@txase txase closed this Dec 6, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants