gitea

Зеркало из https://github.com/go-gitea/gitea
Форк
0
/
web_graceful.go 
55 строк · 1.7 Кб
1
// Copyright 2016 The Gitea Authors. All rights reserved.
2
// SPDX-License-Identifier: MIT
3

4
package cmd
5

6
import (
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

17
func runHTTP(network, listenAddr, name string, m http.Handler, useProxyProtocol bool) error {
18
	return 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
22
func NoHTTPRedirector() {
23
	graceful.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
28
func NoMainListener() {
29
	graceful.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
34
func NoInstallListener() {
35
	graceful.GetManager().InformCleanup()
36
}
37

38
func runFCGI(network, listenAddr, name string, m http.Handler, useProxyProtocol bool) error {
39
	// This needs to handle stdin as fcgi point
40
	fcgiServer := graceful.NewServer(network, listenAddr, name)
41

42
	err := fcgiServer.ListenAndServe(func(listener net.Listener) error {
43
		return fcgi.Serve(listener, http.HandlerFunc(func(resp http.ResponseWriter, req *http.Request) {
44
			if setting.AppSubURL != "" {
45
				req.URL.Path = strings.TrimPrefix(req.URL.Path, setting.AppSubURL)
46
			}
47
			m.ServeHTTP(resp, req)
48
		}))
49
	}, useProxyProtocol)
50
	if err != nil {
51
		log.Fatal("Failed to start FCGI main server: %v", err)
52
	}
53
	log.Info("FCGI Listener: %s Closed", listenAddr)
54
	return err
55
}
56

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.