Welcome to mirror list, hosted at ThFree Co, Russian Federation.

host.go « host « internal - gitlab.com/gitlab-org/gitlab-pages.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: dd9b1c8a272a5221bd934b9a72d55327237a7cb5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
package host

import (
	"net"
	"net/http"
	"strings"
)

// FromString tries to split host port from string, returns host or initial string if fail
func FromString(s string) string {
	host := strings.ToLower(s)

	if splitHost, _, err := net.SplitHostPort(host); err == nil {
		host = splitHost
	}

	return host
}

// FromRequest tries to split host port from r.Host, returns host or initial string if fail
func FromRequest(r *http.Request) string {
	return FromString(r.Host)
}