checkSubdomainIsolation detects if GitHub Enterprise Server has subdomain isolation enabled by attempting to ping the raw. /_ping endpoint on the subdomain. The raw subdomain must always exist for subdomain isolation.
(scheme, hostname string)
| 200 | // checkSubdomainIsolation detects if GitHub Enterprise Server has subdomain isolation enabled |
| 201 | // by attempting to ping the raw.<host>/_ping endpoint on the subdomain. The raw subdomain must always exist for subdomain isolation. |
| 202 | func checkSubdomainIsolation(scheme, hostname string) bool { |
| 203 | subdomainURL := fmt.Sprintf("%s://raw.%s/_ping", scheme, hostname) |
| 204 | |
| 205 | client := &http.Client{ |
| 206 | Timeout: 5 * time.Second, |
| 207 | // Don't follow redirects - we just want to check if the endpoint exists |
| 208 | //nolint:revive // parameters are required by http.Client.CheckRedirect signature |
| 209 | CheckRedirect: func(req *http.Request, via []*http.Request) error { |
| 210 | return http.ErrUseLastResponse |
| 211 | }, |
| 212 | } |
| 213 | |
| 214 | resp, err := client.Get(subdomainURL) |
| 215 | if err != nil { |
| 216 | return false |
| 217 | } |
| 218 | defer resp.Body.Close() |
| 219 | |
| 220 | return resp.StatusCode == http.StatusOK |
| 221 | } |
| 222 | |
| 223 | // Note that this does not handle ports yet, so development environments are out. |
| 224 | func parseAPIHost(s string) (APIHost, error) { |