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.

web_graceful.go 1.7KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. // Copyright 2016 The Gitea Authors. All rights reserved.
  2. // SPDX-License-Identifier: MIT
  3. package cmd
  4. import (
  5. "net"
  6. "net/http"
  7. "net/http/fcgi"
  8. "strings"
  9. "code.gitea.io/gitea/modules/graceful"
  10. "code.gitea.io/gitea/modules/log"
  11. "code.gitea.io/gitea/modules/setting"
  12. )
  13. func runHTTP(network, listenAddr, name string, m http.Handler, useProxyProtocol bool) error {
  14. return graceful.HTTPListenAndServe(network, listenAddr, name, m, useProxyProtocol)
  15. }
  16. // NoHTTPRedirector tells our cleanup routine that we will not be using a fallback http redirector
  17. func NoHTTPRedirector() {
  18. graceful.GetManager().InformCleanup()
  19. }
  20. // NoMainListener tells our cleanup routine that we will not be using a possibly provided listener
  21. // for our main HTTP/HTTPS service
  22. func NoMainListener() {
  23. graceful.GetManager().InformCleanup()
  24. }
  25. // NoInstallListener tells our cleanup routine that we will not be using a possibly provided listener
  26. // for our install HTTP/HTTPS service
  27. func NoInstallListener() {
  28. graceful.GetManager().InformCleanup()
  29. }
  30. func runFCGI(network, listenAddr, name string, m http.Handler, useProxyProtocol bool) error {
  31. // This needs to handle stdin as fcgi point
  32. fcgiServer := graceful.NewServer(network, listenAddr, name)
  33. err := fcgiServer.ListenAndServe(func(listener net.Listener) error {
  34. return fcgi.Serve(listener, http.HandlerFunc(func(resp http.ResponseWriter, req *http.Request) {
  35. if setting.AppSubURL != "" {
  36. req.URL.Path = strings.TrimPrefix(req.URL.Path, setting.AppSubURL)
  37. }
  38. m.ServeHTTP(resp, req)
  39. }))
  40. }, useProxyProtocol)
  41. if err != nil {
  42. log.Fatal("Failed to start FCGI main server: %v", err)
  43. }
  44. log.Info("FCGI Listener: %s Closed", listenAddr)
  45. return err
  46. }