bogkonstantin / android_income_sms_gateway_webhook

Simple Android incoming SMS to URL forwarder
MIT License
388 stars 109 forks source link

Transfer-Encoding: Chunked causes issues with some HTTP servers #49

Closed pmalecka closed 5 months ago

pmalecka commented 1 year ago

Hi bogkonstantin,

first of all, thanks for creating this wonderful tool, I use it daily.

Recently, I have been trying to use your app with Microsoft Teams Webhook API. I found that this API and other APIs as well as some HTTP servers (Apache) have issue with Transfer-Encoding: chunked.

In my case, Microsoft's servers simply respond with: 400 Invalid webhook request - Empty Payload.

If it is not too complicated, I think a simple change could make the app compatible with even more server configs and solutions:

Removal of Transfer-Encoding: Chunked, inclusion of Content-Length header.

Footnotes: Apache issue: https://www.jeffgeerling.com/blog/2017/apache-fastcgi-proxyfcgi-and-empty-post-bodies-chunked-transfer

How to set up a webhook in Teams: https://sankalpit.com/plugins/documentation/how-to-get-channel-webhook-url/

Curl snippet that is closer to the actual request the app sends: curl -ivsS --trace --request POST 'http://testurl/path' --header 'Content-Type: application/json; charset=utf-8' -H 'Transfer-Encoding: chunked' --data '{"text":"sms text"}'

Thanks, Peter

pmalecka commented 1 year ago

Update: The fix is fairly trivial, I created a PR..

Litibe commented 1 year ago

Hi ! I want to receive SMS forwarded into my Python Server with Django Framework. The POST Request is blocked with Django. The solution is to add @csrf_exempt décoration before function AND add into header (in app) content-length : 50000 (random integer) else django block request and the body is empty ! It's possible to add a checkbox for transfert-encoding to delete issus with Python/django to improve the app.

Thanks for the app with your work !

(sorry for my English, i'm French)

bogkonstantin commented 5 months ago

Done in v.2.3.0 - see checkbox Chunked vs Fixed mode