Menu

proxy support

Help
2003-05-07
2004-05-06
  • Bill Zeller

    Bill Zeller - 2003-05-07

    Hi,

    Is proxy support something I would implement or something that would need to be implemented by the xmlrpc++ library?

    I'd like to implement proxy support, but I don't know where to start...

    thanks for the great library!

    -bill zeller

     
    • Chris Morley

      Chris Morley - 2003-05-08

      I honestly don't know what would be involved.

      If something like libcurl supports it, the easiest thing might be to hack the library to optionally use libcurl...

       
      • Artur Klauser

        Artur Klauser - 2003-05-08

        I think the gist of it is rather than sending
          GET / HTTP/1.0 \n\n
        to www.google.com port 80, you send
          GET http://www.google.com:80/ HTTP/1.0 \n\n
        to your.proxy.com on whatever port the proxy is listening to. There is a lot more to it, of course, if you want to control caching, need to authenticate yourself with the proxy, etc. All that results in additional headers that you can optionally send to the proxy after the GET request (and before the second \n).

        http://www.w3.org/Protocols/rfc2616/rfc2616.html

        -r2r-

         
      • Anonymous

        Anonymous - 2003-08-02

        For the most basic proxying, I made the following changes and they work (tested HelloClient/HelloServer with The Grinder's TCPSniffer as proxy http://sourceforge.net/projects/grinder/\).

        1) Add optional proxy host and port parameters to XmlRpcClient constructor, in XmlRpcClient.h

            XmlRpcClient(const char* host, int port, const char* uri=0, const char* proxyHost=0, int proxyPort=80);

        add the variables just like _host and _port:

        // proxy location
        std::string _proxyHost;
        int _proxyPort;
        int useProxy;

        2) and in XmlRpcClient.cpp:

        XmlRpcClient::XmlRpcClient(const char* host, int port, const char* uri/*=0*/,
              const char* proxyHost, int proxyPort)
        ...
          // useProxy = !proxyHost; This construct causes me a Segmentation Fault !!!
          useProxy = 0;
          if (proxyHost) {
             useProxy = 1;
             _proxyHost= proxyHost;
             _proxyPort= proxyPort;
          }
        ...

        3) Provide the full URL for the (grinder) proxy to locate the endpoint:

        std::string
        XmlRpcClient::generateHeader(std::string const& body) {
        ...
          char buff[40];

          sprintf(buff,":%d", _port);
          std::string header =
            "POST http://" + _host + buff + _uri + " HTTP/1.1\r\n"
            "User-Agent: ";
         
          header += XMLRPC_VERSION;
          header += "\r\nHost: ";
          header += _host;

          sprintf(buff,":%d\r\n", _port);
          header += buff;
        ...

        4) In doConnect(), change the call to connect() to:

        bool
        XmlRpcClient::doConnect() {
        ...

          int result=0;
          if ( useProxy) {
             result= XmlRpcSocket::connect(fd, _proxyHost, _proxyPort);
          }
          else
             result= XmlRpcSocket::connect(fd, _host, _port);

          if (!result)
        {
            this->close();
        ...

        5) For a test, in HelloClient.cpp's main() replace part of the original code with:

        main() {
        ...
          int proxyPort = 80;
          if (argc > 3)
             proxyPort = atoi(argv[4]);

          char* proxyHost = 0; // "localhost"
          if (argc > 2)
             proxyHost = argv[3];

          // Use introspection API to look up the supported methods
          XmlRpcClient c(argv[1], port, 0, proxyHost, proxyPort);
        ...

        Make them all, then set up the proxy at port 8001, the HelloServer at 8888, and run the client with:

        HelloClient localhost 8888 localhost 8001

        here the last 2 parameters are the proxy host and proxy port, respectively.

        You can verify the connections with netstat.

         
        • Anonymous

          Anonymous - 2004-04-22

          Hi, tan

          tanks for your changes, I'm looking for something like this. I've added more changes in code, in order to have proxy authentication. It works with my 'i_dont_know' proxy, I think it will work with any proxy.

          First, small change on your code, point 3), in generateHeader:

          if (useProxy)
          {
               header = "POST http://" + _host + buff + _uri + " HTTP/1.1\r\n";
          ...
          else
          {
              header = POST " + _uri + " HTTP/1.1\r\n"
          }

          Second, make a proxy authentication, via 'Proxy-Authentication' header variable:

          header += "Proxy-Authorization: Basic "+encodeBASE64of("user:password")+"\r\n" ;

          the encodeBASE64of method is based on XmlRpcValue::binaryToXml

          For more complex authorization, you can follow Artur's link, before in this thread (http://www.w3.org/Protocols/rfc2616/rfc2616.htm, reference 43)

          Fins ara,

          Jordi

           
    • Bill Zeller

      Bill Zeller - 2003-05-09

      Thanks, I'll look into it.

       
    • Titus Brown

      Titus Brown - 2004-05-06

      I independently implemented a simple version of proxy support.

      See:

      http://issola.caltech.edu/~t/transfer/XmlRpcClient.h.diff

      and

      http://issola.caltech.edu/~t/transfer/XmlRpcClient.cpp.diff

      It would be nice if the functionality was put into a release... doesn't need to be my code, obviously ;).

       

Log in to post a comment.