{"action":"created","issue":{"url":"https://api.github.com/repos/aws/aws-sdk-php/issues/533","labels_url":"https://api.github.com/repos/aws/aws-sdk-php/issues/533/labels{/name}","comments_url":"https://api.github.com/repos/aws/aws-sdk-php/issues/533/comments","events_url":"https://api.github.com/repos/aws/aws-sdk-php/issues/533/events","html_url":"https://github.com/aws/aws-sdk-php/issues/533","id":68949528,"number":533,"title":"Message::fromRawPostData incompatible with POST Content-Type","user":{"login":"gummoe","id":5530093,"avatar_url":"https://avatars.githubusercontent.com/u/5530093?v=3","gravatar_id":"","url":"https://api.github.com/users/gummoe","html_url":"https://github.com/gummoe","followers_url":"https://api.github.com/users/gummoe/followers","following_url":"https://api.github.com/users/gummoe/following{/other_user}","gists_url":"https://api.github.com/users/gummoe/gists{/gist_id}","starred_url":"https://api.github.com/users/gummoe/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/gummoe/subscriptions","organizations_url":"https://api.github.com/users/gummoe/orgs","repos_url":"https://api.github.com/users/gummoe/repos","events_url":"https://api.github.com/users/gummoe/events{/privacy}","received_events_url":"https://api.github.com/users/gummoe/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/aws/aws-sdk-php/labels/awaiting-reply","name":"awaiting-reply","color":"cccccc"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":3,"created_at":"2015-04-16T15:31:48Z","updated_at":"2015-04-22T17:50:56Z","closed_at":null,"body":"*The Problem:*\r\nThe fromRawPostData() function does not appear to work in any situation at the moment. \r\n\r\n*Diagnosis:*\r\nThe Message::fromRawPostData() function relies on json_decode(file_get_contents('php://input'), true) to return an array that is then passed to the Message::fromArray constructor. Unfortunately, Amazon SNS POST requests have a Content-Type of text/plain, which makes it impossible for the json_decode call to return anything other than null. This results in an exception when fromRawPostData() calls the fromArray constructor. \r\n\r\n*Three possible solutions:*\r\n1. Change the SNS POST request Content-Type to 'application/json' or some other acceptable Content-Type\r\n2. Add a private POST body-parsing function to the Message class\r\n3. Leave it up to users to provide a well-formed array to the fromAray() constructor and remove the fromRawPostData() function\r\n\r\nI'd be happy to contribute any work required for solutions 1 or 2! \r\n\r\n"},"comment":{"url":"https://api.github.com/repos/aws/aws-sdk-php/issues/comments/95282434","html_url":"https://github.com/aws/aws-sdk-php/issues/533#issuecomment-95282434","issue_url":"https://api.github.com/repos/aws/aws-sdk-php/issues/533","id":95282434,"user":{"login":"gummoe","id":5530093,"avatar_url":"https://avatars.githubusercontent.com/u/5530093?v=3","gravatar_id":"","url":"https://api.github.com/users/gummoe","html_url":"https://github.com/gummoe","followers_url":"https://api.github.com/users/gummoe/followers","following_url":"https://api.github.com/users/gummoe/following{/other_user}","gists_url":"https://api.github.com/users/gummoe/gists{/gist_id}","starred_url":"https://api.github.com/users/gummoe/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/gummoe/subscriptions","organizations_url":"https://api.github.com/users/gummoe/orgs","repos_url":"https://api.github.com/users/gummoe/repos","events_url":"https://api.github.com/users/gummoe/events{/privacy}","received_events_url":"https://api.github.com/users/gummoe/received_events","type":"User","site_admin":false},"created_at":"2015-04-22T17:50:56Z","updated_at":"2015-04-22T17:50:56Z","body":"Sorry for my delayed response!\r\n\r\nYou are correct that this is the class in question: https://github.com/aws/aws-sdk-php/blob/master/src/Aws/Sns/MessageValidator/Message.php\r\n\r\nYou are also correct that the `fromRawPostData()` function does NOT check the Content-Type of the HTTP request. \r\n\r\nHowever...I may be wrong, but the value obtained from the `file_get_contents('php://input')` returns the entire raw request. An example of a notification from SNS is included below:\r\n\r\n    POST /app_dev.php/event/test/test1 HTTP/1.1\r\n    Host: [sanitized] \r\n    User-Agent: Amazon Simple Notification Service Agent\r\n    Content-Length: 1135\r\n    Accept-Encoding: gzip,deflate\r\n    Connection: close\r\n    Content-Type: text/plain; charset=UTF-8\r\n    X-Amz-Sns-Message-Id: [sanitized]\r\n    X-Amz-Sns-Message-Type: Notification\r\n    X-Amz-Sns-Subscription-Arn: [sanitized]\r\n    X-Amz-Sns-Topic-Arn: [sanitized]\r\n    X-Forwarded-Proto: https\r\n    X-Real-Ip: 72.21.217.131\r\n    \r\n    {\r\n    \"Type\" : \"Notification\",\r\n    \"MessageId\" : \"[sanitized]\",\r\n    \"TopicArn\" : \"[sanitized]\",\r\n    \"Subject\" : \"This is the subject\",\r\n    \"Message\" : \"[sanitized]\",\r\n    \"Timestamp\" : \"2015-04-16T17:37:05.278Z\",\r\n    \"SignatureVersion\" : \"1\",\r\n    \"Signature\" : \"[sanitized]\",\r\n    \"SigningCertURL\" : \"[sanitized]\",\r\n    \"UnsubscribeURL\" : \"[sanitized]\"\r\n    }\r\n\r\nThe `json_decode` function expects the entire string (in this case, `php://input`) to be JSON-encoded, which the raw request is not. I agree with you that the content-type shouldn't matter, but it also seems to be the case that the `fromRawPostData()` function needs to extract the correctly formatted 'payload'-portion of the SNS request before calling `json_decode`. Happy to provide any additional information or tests that would be helpful! "}}