-
Notifications
You must be signed in to change notification settings - Fork 9
/
init.go
106 lines (87 loc) · 2.67 KB
/
init.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
package http
import (
"net/http"
"github.com/quic-go/quic-go/http3"
"github.com/roadrunner-server/http/v5/acme"
"github.com/roadrunner-server/http/v5/common"
"github.com/roadrunner-server/http/v5/config"
bundledMw "github.com/roadrunner-server/http/v5/middleware"
"github.com/roadrunner-server/http/v5/servers/fcgi"
httpServer "github.com/roadrunner-server/http/v5/servers/http11"
http3Server "github.com/roadrunner-server/http/v5/servers/http3"
httpsServer "github.com/roadrunner-server/http/v5/servers/https"
"go.uber.org/zap"
)
// ------- PRIVATE ---------
func (p *Plugin) initServers() error {
if p.cfg.EnableHTTP3() && p.experimentalFeatures {
http3Srv, err := http3Server.NewHTTP3server(p, nilOr(p.cfg), p.cfg.HTTP3Config, p.log)
if err != nil {
return err
}
p.servers = append(p.servers, http3Srv)
}
if p.cfg.EnableHTTP() {
p.servers = append(p.servers, httpServer.NewHTTPServer(p, p.cfg, p.stdLog, p.log))
}
if p.cfg.EnableTLS() {
https, err := httpsServer.NewHTTPSServer(p, p.cfg.SSLConfig, p.cfg.HTTP2Config, p.stdLog, p.log)
if err != nil {
return err
}
p.servers = append(p.servers, https)
}
if p.cfg.EnableFCGI() {
p.servers = append(p.servers, fcgi.NewFCGIServer(p, p.cfg.FCGIConfig, p.log, p.stdLog))
}
return nil
}
func nilOr(cfg *config.Config) *acme.Config {
if cfg.SSLConfig == nil || cfg.SSLConfig.Acme == nil {
return nil
}
return cfg.SSLConfig.Acme
}
func (p *Plugin) applyBundledMiddleware() {
// apply max_req_size and logger middleware
for i := 0; i < len(p.servers); i++ {
switch srv := p.servers[i].Server().(type) {
case *http.Server:
srv.Handler = bundledMw.MaxRequestSize(srv.Handler, p.cfg.MaxRequestSize*MB)
srv.Handler = bundledMw.NewLogMiddleware(srv.Handler, p.cfg.AccessLogs, p.log)
case *http3.Server:
srv.Handler = bundledMw.MaxRequestSize(srv.Handler, p.cfg.MaxRequestSize*MB)
srv.Handler = bundledMw.NewLogMiddleware(srv.Handler, p.cfg.AccessLogs, p.log)
default:
p.log.DPanic("unknown server type", zap.Any("server", p.servers[i].Server()))
}
}
}
func (p *Plugin) unmarshal(cfg common.Configurer) error {
// unmarshal general section
err := cfg.UnmarshalKey(PluginName, &p.cfg)
if err != nil {
return err
}
// unmarshal HTTPS section
err = cfg.UnmarshalKey(sectionHTTPS, &p.cfg.SSLConfig)
if err != nil {
return err
}
// unmarshal H2C section
err = cfg.UnmarshalKey(sectionHTTP2, &p.cfg.HTTP2Config)
if err != nil {
return err
}
// unmarshal uploads section
err = cfg.UnmarshalKey(sectionUploads, &p.cfg.Uploads)
if err != nil {
return err
}
// unmarshal fcgi section
err = cfg.UnmarshalKey(sectionFCGI, &p.cfg.FCGIConfig)
if err != nil {
return err
}
return nil
}