Trolltech Home | Qt4-preview-feedback Home | Recent Threads | All Threads | Author | Date
All threads index page 1

Qt4-preview-feedback Archive, April 2008
Proxy per request


Message 1 in thread

Hi,
I'm not sure whether this is the right list or not. Sorry if it's not.

Currently, QNetworkAccessManager allows setting a global proxy but what if I wanted to use
a different proxy per connection ?

My current use case is a browser that is using a PAC file to configure the proxy. Which means
that one might use a different proxy per connection. Maybe even a different proxy per
protocol (HTTP/HTTPS/FTP)!

Any ideas how to implement this ?

I can subclass QNetworkProxy and return a different proxy HostName but the problem
is that QNetworkProxy is not aware of the host we are connecting to.

Cheers,

-- 
 [ signature omitted ] 

Attachment: signature.asc
Description: Digital signature


Message 2 in thread

Mohammed Sameer wrote:
>Hi,
>I'm not sure whether this is the right list or not. Sorry if it's not.

It is.

>Currently, QNetworkAccessManager allows setting a global proxy but what
> if I wanted to use a different proxy per connection ?

Set the proxy, send one request, then set another proxy, send another 
request.

My goal for Qt 4.5 is to allow you to set a "proxy factory" class, so that 
you can determine which proxy to use based on the connection parameters 
(protocol, host and port).

>My current use case is a browser that is using a PAC file to configure
> the proxy. Which means that one might use a different proxy per
> connection. Maybe even a different proxy per protocol (HTTP/HTTPS/FTP)!
>
>Any ideas how to implement this ?

That's exactly what I want to solve in Qt 4.5. You keep the PAC script 
pre-parsed inside QtScript and you evaluate at every connection.

Right you, you need to roll out your own solution. A simple way is to 
derive from QNetworkAccessManager and override the protected 
createRequest() function. You set the proxy on the manager before calling 
the base implementation of the function.

>I can subclass QNetworkProxy and return a different proxy HostName but
> the problem is that QNetworkProxy is not aware of the host we are
> connecting to.

QNetworkAccessManager::createRequest() is.

-- 
 [ signature omitted ] 

Attachment: signature.asc
Description: This is a digitally signed message part.


Message 3 in thread

On Tue, Apr 01, 2008 at 04:57:32PM +0200, Thiago Macieira wrote:
> Mohammed Sameer wrote:
> >Hi,
> >I'm not sure whether this is the right list or not. Sorry if it's not.
> 
> It is.
> 
> >Currently, QNetworkAccessManager allows setting a global proxy but what
> > if I wanted to use a different proxy per connection ?
> 
> Set the proxy, send one request, then set another proxy, send another 
> request.
> 
> My goal for Qt 4.5 is to allow you to set a "proxy factory" class, so that 
> you can determine which proxy to use based on the connection parameters 
> (protocol, host and port).
> 
> >My current use case is a browser that is using a PAC file to configure
> > the proxy. Which means that one might use a different proxy per
> > connection. Maybe even a different proxy per protocol (HTTP/HTTPS/FTP)!
> >
> >Any ideas how to implement this ?
> 
> That's exactly what I want to solve in Qt 4.5. You keep the PAC script 
> pre-parsed inside QtScript and you evaluate at every connection.
> 
> Right you, you need to roll out your own solution. A simple way is to 
> derive from QNetworkAccessManager and override the protected 
> createRequest() function. You set the proxy on the manager before calling 
> the base implementation of the function.
> 
> >I can subclass QNetworkProxy and return a different proxy HostName but
> > the problem is that QNetworkProxy is not aware of the host we are
> > connecting to.
> 
> QNetworkAccessManager::createRequest() is.

Yup, that's great.

Probably one should detect a proxy failure and try another one in case multiple proxies
can be used. This is a bit tricky I guess but I'm still working on the PAC parser.

I was really impressed when I discovered that QScriptEngine can parse a PAC file ;-)

Thanks for the tips.

-- 
 [ signature omitted ] 

Attachment: signature.asc
Description: Digital signature