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