(host string)
| 95 | } |
| 96 | |
| 97 | func (h *HTTPServer) removeTLD(host string) string { |
| 98 | colon := strings.LastIndexByte(host, ':') |
| 99 | if colon != -1 { |
| 100 | if h, _, err := net.SplitHostPort(host); err == nil { |
| 101 | host = h |
| 102 | } |
| 103 | } |
| 104 | |
| 105 | if strings.HasSuffix(host, ".xip.io") || strings.HasSuffix(host, ".nip.io") { |
| 106 | parts := strings.Split(host, ".") |
| 107 | if len(parts) < 6 { |
| 108 | return "" |
| 109 | } |
| 110 | |
| 111 | name := strings.Join(parts[:len(parts)-6], ".") |
| 112 | |
| 113 | return name |
| 114 | } |
| 115 | |
| 116 | // h.Domains is sorted by decreasing complexity |
| 117 | for _, tld := range h.Domains { |
| 118 | if strings.HasSuffix(host, "."+tld) { |
| 119 | return strings.TrimSuffix(host, "."+tld) |
| 120 | } |
| 121 | } |
| 122 | |
| 123 | dot := strings.LastIndexByte(host, '.') |
| 124 | |
| 125 | if dot == -1 { |
| 126 | return host |
| 127 | } else { |
| 128 | return host[:dot] |
| 129 | } |
| 130 | } |
| 131 | |
| 132 | func (h *HTTPServer) ServeHTTP(w http.ResponseWriter, req *http.Request) { |
| 133 | if h.Debug { |
no outgoing calls