#1 2025-06-04 17:16:13

spanfkyous
Member
Registered: 2025-06-04
Posts: 3

dns custom for http client

Hi,

Does mORMot2 support custom DNS? I want to select a suitable IP address for the Http Client in code.

For example: test.com resolves to 1.1.2.2 (which is either a faulty service or unreachable due to network issues) and 1.1.1.1 (which is still available).

In the current implementation, openbind seems connect to the first resolved address from the system, and there's no way to temporarily exclude 1.1.2.2 through code.

Offline

#2 2025-06-04 17:37:10

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 15,062
Website

Re: dns custom for http client

You may try RegisterKnownHost() if you want to force an IP for a given host name.

Offline

#3 2025-06-05 02:25:56

spanfkyous
Member
Registered: 2025-06-04
Posts: 3

Re: dns custom for http client

Thank you.

I looked into RegisterKnownHost, and it maps a specific domain name to a specific IP address.
What I actually want is to block certain IP addresses.
Let me give a more specific example: for test.com, if it resolves to 1.1.2.2, I want to avoid selecting it as the socket ip destination. But if it resolves to other IPs by DNS, I want to allow them and not processed.

Offline

#4 2025-06-05 07:54:29

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 15,062
Website

Re: dns custom for http client

Just out of interest, do you know any library or OS API which supports such an 'exclusion' feature?

Offline

#5 2025-06-05 13:02:44

spanfkyous
Member
Registered: 2025-06-04
Posts: 3

Re: dns custom for http client

Previously, I used Oberbyte ICS as the HTTP client, but unfortunately it doesn't support Lazarus, so I switched to mORMot.

There is an event in ICS's THttpCli:
    TSelectDnsEvent = procedure(Sender : TObject;  DnsList     : TStrings;    var NewDns  : String) of object;
ref:https://svn.overbyte.be/svn/ics/trunk/Source/OverbyteIcsHttpProt.pas

This event will be triggered when the DNS resolve is done.
DnsList stores all IP addresses resolved by DNS, NewDns is the IP address selected by THttpCli to do future connection, I can modify it in the event.

Offline

Board footer

Powered by FluxBB