colyseus / uWebSockets-express

Express API compatibility layer for uWebSockets.js
https://npmjs.com/package/uwebsockets-express
MIT License
56 stars 13 forks source link

Content-Length > actual size will result in Error: socket hang up #9

Closed Vidski closed 3 years ago

Vidski commented 3 years ago

Sending a request, where the Content-Length header is bigger than the actual content size will result in a Error: socket hang up. In my opinion, it should throw a 400 Bad Request.

Example(Valid):

POST /users/login HTTP/1.1
Host: 127.0.0.1:2567
Host: 127.0.0.1:2567
User-Agent: UnityPlayer/2020.3.13f1 (UnityWebRequest/1.0, libcurl/7.75.0-DEV)
Accept: */*
Accept-Encoding: identity
Content-Type: application/x-www-form-urlencoded
X-Unity-Version: 2020.3.13f1
Content-Length: 38

email=mymail%40gmail.com&password=test

Result: 200 OK

Example(Invalid): Content-Length > 38

POST /users/login HTTP/1.1
Host: 127.0.0.1:2567
Host: 127.0.0.1:2567
User-Agent: UnityPlayer/2020.3.13f1 (UnityWebRequest/1.0, libcurl/7.75.0-DEV)
Accept: */*
Accept-Encoding: identity
Content-Type: application/x-www-form-urlencoded
X-Unity-Version: 2020.3.13f1
Content-Length: 39

email=mymail%40gmail.com&password=test

Result: Error: socket hang up

endel commented 3 years ago

Thank you @Vidski, I've just released version uwebsockets-express@1.1.10 with a fix for this and also the aborting request problem!

Let me know if this works for you! If you happen to have any other issue please let me know too :)