vinipsmaker / tufao

An asynchronous web framework for C++ built on top of Qt
http://vinipsmaker.github.io/tufao/
GNU Lesser General Public License v2.1
589 stars 179 forks source link

What is the maximum amount of data for a single transfer? #99

Open Lucas2525117 opened 3 years ago

Lucas2525117 commented 3 years ago

Question: During self-test,the Web transfers data to the application through the tufao library,But when the amount of transmitted data is 128KB, the application does not receive the data message through the signal "newMessage", so I want to ask:“What is the maximum amount of data for a single transfer?”

Thanks!

vinipsmaker commented 3 years ago

The project doesn't put an upper limit to amount of read data:

https://github.com/vinipsmaker/tufao/blob/4d89b6c98f65db0b08ed7bf5ce223a489f4be77c/src/httpserverrequest.cpp#L130

And this is actually a problem as it makes your application subject to DoS attacks. It'd be better if it did put a limit, but I'm no longer maintaining this project and will not write such changes.

But when the amount of transmitted data is 128KB, the application does not receive the data message through the signal "newMessage"

I'm guessing this is a different problem. Are you writing a response? When the end of current message is reached, it stops reading new requests entirely:

https://github.com/vinipsmaker/tufao/blob/4d89b6c98f65db0b08ed7bf5ce223a489f4be77c/src/httpserverrequest.cpp#L246-L247

Only when you reply to current request through the HttpServerResponse class...

https://github.com/vinipsmaker/tufao/blob/4d89b6c98f65db0b08ed7bf5ce223a489f4be77c/src/httpserverresponse.cpp#L378

...the HttpServerRequest class will resume reading new messages:

https://github.com/vinipsmaker/tufao/blob/4d89b6c98f65db0b08ed7bf5ce223a489f4be77c/src/httpserver.cpp#L133-L134

That's how I can ensure you'll not get data() signals to the wrong request when HTTP pipelining is at play.

Lucas2525117 commented 3 years ago

In fact, my application uses the "newMessage" signal to get the message sent to me from the web. At the same time, one problem I want to talk about is that my application communicates with the front end through websocket. Under the premise of websocket communication, some short messages can be received through the "newMessage" signal, but longer messages are transmitted. As mentioned in my question, the web transmits a 128KB message through websocket , But the application did not receive the newMessage signal. tufao/src/websocket.cpp if (priv->frame.fin()) { // FINAL if (priv->frame.isControlFrame()) { evaluateControlFrame(); } else { if (priv->frame.opcode() == FrameType::CONTINUATION) { // CONTINUATION QByteArray chunk(priv->fragment); priv->fragment.clear(); emit newMessage(chunk); } else { // NON-CONTINUATION QByteArray chunk(priv->payload); priv->payload.clear(); emit newMessage(chunk); } } }

vinipsmaker commented 3 years ago

Oh, I didn't realize you were talking about the WebSocket support. Sorry.

There is a bug in the payload parsing code for the WebSocket protocol.

Lucas2525117 commented 3 years ago

Can you elaborate more? What is the specific cause of the error?

Thanks!

vinipsmaker commented 3 years ago

Can you elaborate more? What is the specific cause of the error?

Unfortunately I wrote the code long ago and don't remember the details. Nor do I have time to maintain this project anymore, so you'll have to look by yourself (the file is src/websocket.cpp).

Although I don't have the time to maintain this project any longer, I still do remember the HTTP classes quite well. If the bug was related to HTTP, I could offer a little helping hand.

harryhdk commented 3 years ago

Can you elaborate more? What is the specific cause of the error?

Thanks!

Question: During self-test,the Web transfers data to the application through the tufao library,But when the amount of transmitted data is 128KB, the application does not receive the data message through the signal "newMessage", so I want to ask:“What is the maximum amount of data for a single transfer?”

Thanks!

Have you solved the problem?

vinipsmaker commented 3 years ago

@Lucas2525117 can you test if the PR https://github.com/vinipsmaker/tufao/pull/101 fixes the issue for you? I'm gonna merge it soon.