Simple proxy, using two QTcpProxy
Sorry for my bad English.
I need to make a simple proxy (without auth, etc). Every connection must be in separated thread. It must transer data from/to browser and remote server.
My variant looks like this:
I have made a class Server (: QTcpServer), with overloaded incomingConnection
When incomingConnection emitted, I create new object of class Transfer, which create a new thread.
In new thread I create an object of class TransferHandler, which create two sockets(named in and out) and connect signals readyRead from in to slot inReadyRead, from out to outReadyRead. When these signals emited, I just copy data from one into another (using readAll()).
When signals disconnected() emitted, I just close sockects an delete objects.
In method run() of thread object I call method exec().
Answers for all requests are come. But in the browser there is only a part of answer(I think only first package was come). Then, the browser hangs in connected state, but did not gets data.
If try to transfer data without events(did not call exec()), but just in cycle and using waitForReadyRead() all data transfers in to browser/server, but there is very long ping.--
I went quickly through your code, some comments:
- it's not useful to spawn a thread each time, you might want to keep working in the main thread and using just signals / slots (will work nicely unless you have to scale drastically)
- as your transferhandler class is waiting on your socket, you'd rather connect signals and slots as son as you've created the objects (otherwise, you might lose some events)
- you mix synchronous (waitForxxx) and asynchronous, it's not easy to follow
So far, without compiling it, I didn't see any trivial issue, I might have a further look later.
Thanks, I'll rewrite code using only signals ans slots and paste sources here.
Ok. I've rewrote proxy.
This archive contains a project, with partially working proxy. It works fine with GET reqests, but doesn't work with POST.
I get "400 bad request", when uploading file. And http://ping.eu/ping/ also doesn't work.
What is wrong?
Is anyone could answer me?
Hi All, and DmT021!
I very-very interested in you QT proxy server! Could you please contact me here or by the mail: firstname.lastname@example.org
If anyone knows someone about completed QT HTTP proxy server, please contack me :)