RestRequest Param Host not autocreate - rest

Using Delphi 10, I have a TRESTClient with TRESTRequest to access an API.
I can't reach the server using its DNS hostname. There is a DNS problem on my network, and using the hostname I reach the wrong server. So I must use the server's IP address instead. But the API expects the Host request header to be the DNS hostname.
So I try to put a header like Host: auth-x.de in the request, like this:
RESTClient1.AddParameter('Auto', 'blau', TRESTRequestParameterKind.pkHTTPHEADER);
RESTClient1.AddParameter('Host', 'auth-x.de', TRESTRequestParameterKind.pkHTTPHEADER);
But when I send the request to the IP address, the component overwrites my Host header with the IP address.
The header Auto: blau (just for test) is sent just fine.
How can I prevent my Host header from being automatically overwritten?

Related

Connecting from webserver to SFTP server / firewall issues

I am trying to connect to a remote SFTP server via Phpleagues Flysystem.
The remote SFTP server's firewall only allows the IP address of our webserver.
In my understanding, when a client accesses our website an API request from the client is sent to our backend webserver. This webserver in turn is sending a request to the remote SFTP server. However, this does not seem to work and I assume that the request being sent from our webserver is sent with the client's IP address (instead of the one from our webserver).
Is there an option to sent the internal request from webserver to SFTP server with the IP address from our webserver in order to pass the firewall?
(It does work when I am sending a request from our company network, whose IP address is also registered in the firewall of the remote SFT server. As soon as I try from another network, the same request fails.)

How to get IP of backend selected?

I am using HAProxy with multiple backends and some ACLs to select a backend, I want my client (for testing purposes and etc) to know the ip of the backend that was selected.
For example, Client sends request to HAProxy which loadbalances between ip A and ip B. In the response header, I want the ip of A if A was selected by HAProxy and I want the ip of B if B was selected. I know of %[dst] but it returns the ip of the HAProxy server instead.
Right now I'm putting http-response set-header X-Forwarded-Host %[dst]:%[dst_port] in the frontend and it is returning the ip and port of the HAProxy
found the answer, its %si:%sp. cbonte.github.io/haproxy-dconv/1.7/configuration.html#8.2.4

Website with dedicated IP Address, still uses shared server IP

Using cPanel WHM I have created a website hosting with Dedicated IP Address,
I'm planning to use it with the IP Address instead of a domain (e.g. http://1.2.3.4/script.php)
It opens, script also works fine.
The only issue is the IP address it uses isn't dedicated, it still uses server's shared IP.
I checked by CURL equivalent file_get_contents('http://myip.is') , the IP is the shared IP of server not the IP is use in URL or dedicated to it.
After a lot of tries, I realized the issue is because of CURL, apparently it still uses the server's main IP Address.
I managed to fixed this by adding the following to my CURL function
// Changing 1.2.3.4 with websites real IP
$website_ip = '1.2.3.4';
curl_setopt($curl, CURLOPT_INTERFACE, $website_ip);

can we set our ip address to be used in Perl SSLeay request?

I'm modifying CGIProxy to be enable to pass client IP address to remote/target, so remote will identify that the request is from client (not proxy server). Is it possible to do this thing? CGIProxy uses SSLeay for sending request to SSL server. But I need to pass client IP address through all protocol provided (http, https, ftp). I'm not really understand about both of proxy concept and network programming.
Usually a proxy is not source-transparent, e.g. it will have it's own address as the client address in the connection to the target server and not the original client address. This is especially true for a CGI-script working as a proxy like in your case. This behavior is independent from using a TLS or a plain TCP connection.
But some (often misconfigured) servers check for an X-Forwarded-For request header to determine the original client IP. This header can be set from inside the proxy, but again this is independent from using TLS or plain TCP.

How can I tell whether a controller action was requested by DNS or IP?

On my WebDev server, I'm trying to test whether a controller's action was requested through its raw IP, or by its DNS. I've tried looking at the controller's HttpRequest.Url.HostNameType, but it seems to resolve to a DNS even if I enter my local IP in the browser. Any ideas? Thanks in advance.
That information is passed in the Host header of an HTTP request, so you should be able to access it like this:
var requestedHost = Request.Headers["Host"];
If the request was for an IP address, that IP address string should be returned. Otherwise, it will be whatever hostname they used.
HttpContext.Current.Request.Url.Authority
Gets the Domain Name System (DNS) host name or IP address and the port number for a server.
Uri baseUri = new Uri("http://www.contoso.com:8080/");
Uri myUri = new Uri(baseUri,"shownew.htm?date=today");
Console.WriteLine(myUri.Authority);
Output: www.contoso.com:8080