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

cowboy multi frame http request handling #868

Closed
aoeking opened this issue Aug 4, 2015 · 4 comments
Closed

cowboy multi frame http request handling #868

aoeking opened this issue Aug 4, 2015 · 4 comments

Comments

@aoeking
Copy link

aoeking commented Aug 4, 2015

Hi All,

Recently we made REST calls using android application. When the connection is on LTE the system worked fine and when the connection is slow it appeared that cowboy did not receive the body of the POST request. Investigations shows us that when the connection is slow android it self sends the http packets by multiple frames.

When it comes to the cowboy it did not process the body part even thought the data received to the ranch_tcp module. But after putting few logs in to "recv(Socket, Length, Timeout)" function in ranch_tcp we got the data but in separate function calls. Please refer the attachment for tcpdump image.

ranch_tcp recv :- {ok,<<"POST /rest/subscribers HTTP/1.1\r\nContent-Type: application/json\r\nContent-Length: 336\r\nHost: xxx.xx.xx.xxx:80\r\nConnection: Keep-Alive\r\n\r\n">>}

ranch_tcp recv :- {ok,<<"{"email":"xxxxxxxxxxxxxxxxx@xxxxxxxxxxxxx.com","password":"google pwd","imsi":"xxxxxxxxxxxxxxx","imei":"xxxxxxxxxxxxxxx","oauth_type":"google","nickname":"rsfggvg","image_url":"aHR0cHM6Ly9saDUuZ29vZ2xldXNlcmNvbnRlbyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy/c3o9NTA=","mobile":"xx@xxxxxxxxx"}">>}

test

Any idea how to solve this.

Thanks & Best Regards,
Nuwan

@essen
Copy link
Member

essen commented Aug 6, 2015

I did not fully understand this. There should be no issue with data arriving in separate packets, Cowboy does the reassembly itself. Can you show what the code you've written to handle the body looks like, and also give me what Cowboy version you're using?

@aoeking
Copy link
Author

aoeking commented Aug 13, 2015

I used the following code to catch the body and i am using the master branch for my developments.

{_, Body, _} = cowboy_req:body(Req),

@essen
Copy link
Member

essen commented Aug 13, 2015

You have to keep track of the third element of the returned tuples for one, and you may need to call body more than once if it doesn't return 'ok' in the first element of the returned tuple.

@essen
Copy link
Member

essen commented Aug 15, 2015

Hope that helped. Closing, thanks!

@essen essen closed this as completed Aug 15, 2015
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

No branches or pull requests

2 participants