PDA

View Full Version : Using QHttp / QUrl with a hard-coded DNS entry



cboles
27th November 2014, 00:06
I'm sending a request to a virtual server using QUrl / QHttp that is of the form

http://www.myserver.com/path/request.php?var1=x&var2=y

and this is working fine. For certain tests we would like to not use a DNS server and instead hard-code the DNS entry of www.myserver.com to an IPv4 address of our choosing. I know I can do this with a hosts file entry, but I would like to do this only within my app and not affect the rest of the OS. Further, because the virtual server wants to see the correct hostname in the URL, I can't simply make a request like this:

http://1.2.3.4/path/request.php?var1=x&var2=y

I haven't gone through the QtNetwork source yet, but I'm wondering if there is a way to specify an "internal" DNS provider or internal hosts mapping so that it does not go through the whole network stack to make these DNS lookups and still has the hostname in the URL, all the while having this only affect a single instance of my app?

ChrisW67
27th November 2014, 11:35
Name lookups are likely to use the QHostInfo class static members. There seems to be no obvious way to subvert this internally.

cboles
28th November 2014, 12:13
Name lookups are likely to use the QHostInfo class static members. There seems to be no obvious way to subvert this internally.

It's looking somewhat doable, but I have to peek into qhostinfo_p.h to pull it off. There is a global instance of a QHostInfoLookupManager that runs a thread pool for DNS lookups but also maintains a public QHostInfoCache which has a put() method where I could stuff a non-DNS lookup cache entry for my hostname. If I do this before I use QHttp it might work... will let everyone know if this works out.

ChrisW67
30th November 2014, 19:03
BTW, you should not be writing new code to use QHttp

cboles
2nd December 2014, 20:48
BTW, you should not be writing new code to use QHttp

Thanks - understood. This code is 7 years old, but even with QNetworkAccessManager I think the hostname resolution is going to work the same.