Overview
Features
Download
Documentation
Community
Add-Ons & Services

bug in Poco::Net::HttpClientSession when using proxy

A general discussion forum.

bug in Poco::Net::HttpClientSession when using proxy

Postby skyxie » 30 Sep 2011, 10:44

Hi,

I believe this is a bug of Poco 1.4.2

below is is the testing code.
If not using proxy, the below code can works; but if session proxy is enabled, the HTTP GET header will like below:
Code: Select all
GET http://www.example.com:80http://www.example.com/query?r=xxx HTTP/1.1


To fix this problem, I think the HTTPClientSession.cpp code should be changed from:
Code: Select all
    212         if (!_proxyHost.empty())
    213         {
    214             request.setURI(proxyRequestPrefix() + [color=#BFBF00]request.getURI()[/color]);
    215             proxyAuthenticate(request);
    216         }

to
Code: Select all
    212         if (!_proxyHost.empty())
    213         {
    214             request.setURI(proxyRequestPrefix() + [b]Poco:URI(request.getURI()).getPathEtc()[/b]);
    215             proxyAuthenticate(request);
    216         }


other HTTPRequest URI must be set with only the PathEtc part.(ie. no scheme,host,port)

I may not access this forum for long time, if you have different option, also post to my mail box (xrg_soft(at)163.com) is appreciated!

Testing code:
Code: Select all
#include <Poco/Net/HTTPClientSession.h>
#include <Poco/Net/HTTPRequest.h>
#include <Poco/URI.h>
#include <string>

int main(void)
{
    // no error handling ...

    std::string strURI = "http://www.example.com/query?r=xxx";
    Poco::URI uri(strURI);

    Poco::Net::HTTPClientSession session;
    session.setHost(uri.getHost());
    session.setPort(uri.getPort());

    // Porxy switch:
    //  session.setProxy(<proxyHost>, <proxyPort>);

    Poco::Net::HTTPRequest req("HTTP/1.1");
    req.setURI(strURI);  // in case of this URI is full, the bug may occurs.

    session.sendRequest(req);

    return 0;
}
skyxie
 
Posts: 3
Joined: 30 Sep 2011, 08:55

Re: bug in Poco::Net::HttpClientSession when using proxy

Postby guenter » 30 Sep 2011, 14:08

User error: you should change:
Code: Select all
req.setURI(strURI);
to
Code: Select all
req.set(uri.getPathEtc());
and it will work with and without proxy.
guenter
 
Posts: 1110
Joined: 11 Jul 2006, 16:27
Location: Austria

Re: bug in Poco::Net::HttpClientSession when using proxy

Postby skyxie » 30 Sep 2011, 15:14

Hi,

Thanks!

Yes. calling req.setURI(uri.getPathEtc()) will always works.

But why the full uri works for non-proxy and can not works for proxy enabled?
This will make the poco user confused, especially the new user likes me :(

So I suggest:
either change the code of HTTPClientSession.cpp
or
at the method documentation for HTTPRequest setURI(as well as the HTTPRequest ctor) method, point out that only uri.getPathEtc() can be used.

BR, xrg
skyxie
 
Posts: 3
Joined: 30 Sep 2011, 08:55


Return to General Discussion

Who is online

Users browsing this forum: No registered users and 3 guests

cron