Results 1 to 9 of 9

Thread: How to make a proxy server?

  1. #1
    Join Date
    May 2009
    Posts
    5
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default How to make a proxy server?

    Hi, I'm Passerby, a newbie to Qt.

    I've been trying to make a local proxy server for web browsers (HTTP protocol; something like BFilter) with Qt.
    I thought the QNetworkAccessManager would be the key class, but it doesn't seem to be able to handle requests from other places. So I checked the whole QtNetwork module, and found that only QLocalServer and QTcpServer provide a listen() method. But they are quite different from QNetworkReply or QHttp. They are also not able to set a fixed local port to listen to.

    So which classes should I use, in order to receive HTTP requests from a specified port, and deal with that like a proxy server?

    Thanks.
    Nightmare be with us

  2. #2
    Join Date
    May 2009
    Posts
    61
    Thanks
    5
    Thanked 6 Times in 6 Posts
    Qt products
    Qt3 Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: How to make a proxy server?

    Mmmh... help says:
    QTcpServer::bool listen ( const QHostAddress & address = QHostAddress::Any, quint16 port = 0 )

    so the port can be set. My servers are all QTcpServers, works fine.

  3. The following user says thank you to auba for this useful post:

    Passerby (6th June 2009)

  4. #3
    Join Date
    May 2009
    Posts
    5
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to make a proxy server?

    Yes OK QTcpServer::listen() supports port#, but I'm trying to build a proxy server, not a game/IM/etc server.
    So is QTcpServer the only choice, and I'll have to extract the information from the TCP connection and reassemble the HTTP request all by myself?
    Last edited by Passerby; 16th May 2009 at 08:29.
    Nightmare be with us

  5. #4
    Join Date
    May 2009
    Posts
    5
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to make a proxy server?

    Hi, it's me again.

    So now I'm using QTcpServer. For every new connection, I use a QHttp to send request, and write the response back to the socket (please tell me if this is stupid; I just thought it would be easier to apply filter).

    Everything works fine, except for the Transfer-Encoding: chunked response. All browsers will immediately close the socket after one chunk and act as "page can not be displayed".

    I googled and wiki-ed the definition of chunked encoding, did some test, and finally found out that what QHttp::readAll() return is no longer chunked.

    Then I tried removing the Transfer-Encoding header before writing. That works, but leads to another problem: by the definition of chunked encoding, the message-sender is allowed to "append" headers after the message body (so-called "trailer"). So if I remove the Transfer-Encoding header, the trailer will be lost (or treated as improper message, depending on how QHttp handle; I haven't tested that yet).

    I can re-chunk the message by "repair"ing the size-line of each chunk, but still, I'll have to determine where's the trailer part and avoid counting their length. Since the size-line is already removed by QHttp, I can't think of anything except the colon and space as the identifier of trailer. But there's always chance that the message body contains a colon and space.

    So can anyone please tell me how to deal with the chunked encoding transfer? Many thanks.
    Last edited by Passerby; 6th June 2009 at 08:16.
    Nightmare be with us

  6. #5
    Join Date
    Apr 2009
    Posts
    29
    Thanks
    2
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11

    Default Re: How to make a proxy server?

    Hi Passerby,

    this is a very interesting project since the development of BFilter is discontinued for over two years now. Do you have developed your program further? I have tried to program a proxy but I don't found out how to correctly to handle post requests of bigger files from the browser.

    Greetings

  7. #6
    Join Date
    Jan 2006
    Location
    Belgium
    Posts
    1,938
    Thanked 268 Times in 268 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Wiki edits
    20

    Default Re: How to make a proxy server?

    For any questions about the protocols you handle in the proxy, check the rfc's
    http://www.w3.org/Protocols/rfc2616/rfc2616.html

  8. #7
    Join Date
    May 2008
    Posts
    276
    Thanks
    13
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to make a proxy server?

    Me too, I am developing a proxy in Qt.
    It works, but not for all website.
    Part of the source code can be found here

    http://stackoverflow.com/questions/7...ed-java-script

    Check for example this video webserver 87.22.235.24.
    It hangs...
    Regards

  9. #8
    Join Date
    Apr 2009
    Posts
    29
    Thanks
    2
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11

    Default Re: How to make a proxy server?

    Hi giusepped,

    have you solved the problem? Is the source code available so I can test it, maybe I can help. I'm looking forward for an alternative for bfilter since the project is unfortunately discontinued.

    regards

  10. #9
    Join Date
    May 2008
    Posts
    276
    Thanks
    13
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to make a proxy server?

    Quote Originally Posted by Fred View Post
    Hi giusepped,

    have you solved the problem? Is the source code available so I can test it, maybe I can help. I'm looking forward for an alternative for bfilter since the project is unfortunately discontinued.

    regards
    I solved by doing myself a header parser, and an unzipper for gzipped sites. But do not work always. I am in trouble for just one site. If you can help, I can share the code with you. Please, reply in that case by email or pm.
    Regards

Similar Threads

  1. Replies: 3
    Last Post: 29th November 2009, 20:24
  2. Replies: 0
    Last Post: 22nd February 2009, 13:15
  3. QHttp proxy problem
    By andre.rigon in forum Qt Programming
    Replies: 2
    Last Post: 28th September 2008, 21:19
  4. Window OS make distclean && qmake && make one line
    By patrik08 in forum General Programming
    Replies: 4
    Last Post: 22nd March 2007, 10:43
  5. Compiling with Qmake/Make
    By VireX in forum Newbie
    Replies: 25
    Last Post: 22nd February 2007, 05:57

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.