You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

44 lines
997 B

  1. // +build !windows
  2. // Copyright 2016 The Gitea Authors. All rights reserved.
  3. // Use of this source code is governed by a MIT-style
  4. // license that can be found in the LICENSE file.
  5. package cmd
  6. import (
  7. "crypto/tls"
  8. "net/http"
  9. "code.gitea.io/gitea/modules/log"
  10. "github.com/facebookgo/grace/gracehttp"
  11. )
  12. func runHTTP(listenAddr string, m http.Handler) error {
  13. return gracehttp.Serve(&http.Server{
  14. Addr: listenAddr,
  15. Handler: m,
  16. })
  17. }
  18. func runHTTPS(listenAddr, certFile, keyFile string, m http.Handler) error {
  19. config := &tls.Config{
  20. MinVersion: tls.VersionTLS10,
  21. }
  22. if config.NextProtos == nil {
  23. config.NextProtos = []string{"http/1.1"}
  24. }
  25. config.Certificates = make([]tls.Certificate, 1)
  26. var err error
  27. config.Certificates[0], err = tls.LoadX509KeyPair(certFile, keyFile)
  28. if err != nil {
  29. log.Fatal(4, "Failed to load https cert file %s: %v", listenAddr, err)
  30. }
  31. return gracehttp.Serve(&http.Server{
  32. Addr: listenAddr,
  33. Handler: m,
  34. TLSConfig: config,
  35. })
  36. }