(cfg config.HTTP)
| 171 | } |
| 172 | |
| 173 | func serve(cfg config.HTTP) { |
| 174 | var h http.Handler |
| 175 | ln := newListener(cfg.ListenAddr) |
| 176 | |
| 177 | h = http.HandlerFunc(serveHTTP) |
| 178 | if cfg.ForceAutocertHandler { |
| 179 | if autocertManager == nil { |
| 180 | panic("BUG: autocertManager is not inited") |
| 181 | } |
| 182 | addr := ln.Addr().String() |
| 183 | parts := strings.Split(addr, ":") |
| 184 | if parts[len(parts)-1] != "80" { |
| 185 | log.Fatalf("`letsencrypt` specification requires http server to listen on :80 port to satisfy http-01 challenge. " + |
| 186 | "Otherwise, certificates will be impossible to generate") |
| 187 | } |
| 188 | h = autocertManager.HTTPHandler(h) |
| 189 | } |
| 190 | log.Infof("Serving http on %q", cfg.ListenAddr) |
| 191 | if err := listenAndServe(ln, h, cfg.TimeoutCfg); err != nil { |
| 192 | log.Fatalf("HTTP server error on %q: %s", cfg.ListenAddr, err) |
| 193 | } |
| 194 | } |
| 195 | |
| 196 | func newServer(ln net.Listener, h http.Handler, cfg config.TimeoutCfg) *http.Server { |
| 197 | // nolint:gosec // We already configured ReadTimeout, so no need to set ReadHeaderTimeout as well. |
no test coverage detected