All predicatesShow sourcehttp_host.pl -- Obtain public server location

This library finds the public address of the running server. This can be used to construct URLs that are visible from anywhere on the internet. This module was introduced to deal with OpenID, where a request is redirected to the OpenID server, which in turn redirects to our server (see http_openid.pl).

The address is established from the settings http:public_host and http:public_port if provided. Otherwise it is deduced from the request.

Source http_public_url(+Request, -URL) is det
True when URL is an absolute URL for the current request. Typically, the login page should redirect to this URL to avoid losing the session.
Source http_public_host_url(+Request, -URL) is det
True when URL is the public URL at which this server can be contacted. This value is not easy to obtain. See http_public_host/4 for the hardest part: find the host and port.
Source http_public_host(?Request, -Hostname, -Port, +Options) is det
Current global host and port of the HTTP server. This is the basis to form absolute address, which we need for redirection based interaction such as the OpenID protocol. Options are:
global(+Bool)
If true (default false), try to replace a local hostname by a world-wide accessible name.

This predicate performs the following steps to find the host and port:

  1. Use the settings http:public_host and http:public_port
  2. Use X-Forwarded-Host header, which applies if this server runs behind a proxy.
  3. Use the Host header, which applies for HTTP 1.1 if we are contacted directly.
  4. Use gethostname/1 to find the host and http_current_server/2 to find the port.
Arguments:
Request- is the current request. If it is left unbound, and the request is needed, it is obtained with http_current_request/1.
Source http_current_host(?Request, -Hostname, -Port, +Options) is det
deprecated
- Use http_public_host/4 (same semantics)
Source primary_forwarded_host(+Spec, -Host) is det[private]
x_forwarded host contains multiple hosts seperated by ', ' if there are multiple proxy servers in between. The first one is the one the user's browser knows about.
Source global_host(+HostIn, -Host)[private]
Globalize a hostname. Used if we need to pass our hostname to a client and expect the client to be able to contact us. In this case we cannot use a name such as `localhost' or the plain hostname of the machine. We assume (possibly wrongly) that if the host contains a '.', it is globally accessible.

If the heuristics used by this predicate do not suffice, the setting http:public_host can be used to override.