Home > database >  In Golang http client, what does Host mean in MaxConnsPerHost and MaxIdleConnsPerHost?
In Golang http client, what does Host mean in MaxConnsPerHost and MaxIdleConnsPerHost?

Time:07-04

In MaxConnsPerHost and MaxIdleConnsPerHost in GO HTTP package, is "Host" a domain(i.e., yahoo.com) or an IP address? The actual meaning of "Host" will affect my settings for the connection pool.

CodePudding user response:

The host is the following part of a URL:

http://THIS.IS.THE.HOST/path/to/endpoint
       ^^^^^^^^^^^^^^^^

The underlined part of the URL is the host. The host can either be a domain name or an IP address - it depends on the URL you use. Note that it does not depend on the server answering the request.

For example, in the following:

http://127.0.0.1/api/list-all

The host is 127.0.0.1. But in the following:

http://example.com/api/list-all

The host is example.com.

If you have two servers configured like the following:

                     ┌───── HTTP Server 1 (10.20.30.40)
                     │        ├ www.foo.com (default)
                     │        └ www.bar.com
                     │
  DNS Load ──────────┤
  Balancer           │
                     └───── HTTP Server 2 (11.22.33.44)
                              └ www.bar.com (default)

Then http://www.bar.com is considered the same host even though it is served by two different IP addresses (10.20.30.40 and 11.22.33.44 - note: DNS load balancers do not handle HTTP request instead it handles DNS requests and will send different IP addresses to different clients to load-balance)

However 11.22.33.44 and www.bar.com are considered two different hosts even though both serve the exact same content.

Similarly www.foo.com and www.bar.com and 10.20.30.40 are considered 3 different hosts even though they are all served by the same server and same IP address (if the load balancer for www.bar.com resolve to 10.20.30.40).

CodePudding user response:

“Host” in http://www.example.com/abc/def is www.example.com.

The host may correspond to multiple IP addresses. This is normal.

  • Related