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

Exmaple for onData handler instead of collectData #34

Open
mrdeveloperdude opened this issue Jan 31, 2017 · 1 comment
Open

Exmaple for onData handler instead of collectData #34

mrdeveloperdude opened this issue Jan 31, 2017 · 1 comment

Comments

@mrdeveloperdude
Copy link

I am having trouble implementing this example but by using onData() handler instead of collectData():

https://github.com/azadkuh/qhttp/tree/master/example/postcollector

Would you be so kind as to give us some pointers?

In short, my naive approach looks like this:

req->onData([=](QByteArray data) {
		qDebug()<<"DATA RECEIVED: "<<data.size()<<": "<<data;
	});

	req->onEnd([=]() {
		qDebug()<<"DATA ENDED: ";
		res->setStatusCode(qhttp::ESTATUS_OK);

		QByteArray body="<html><body><form method=\"post\" action=\"./\"><input type=\"file\" name=\"file\"><input type=\"submit\" value=\"send\"></form></body></html>";
		res->addHeader("content-type","text/html");
		res->addHeader("connection", "keep-alive");
		res->addHeaderValue("content-length", body.length());
		res->end(body);
	});

When I send data to it, onData() never gets called, or gets called with 12 byte string unrelated to what I actually sent. onEnd() gets called every time.

Thanks!

@mrdeveloperdude
Copy link
Author

I just noticed that by simply commenting out the onEnd handler suddenly the onData handler gets called. And by commenting out only the res->end(body); line I see that the onEnd handler is called 3 times, one at start, one in the middle and one at end. This seems like a bug to me.

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

1 participant