forked from roadrunner-server/http
-
Notifications
You must be signed in to change notification settings - Fork 0
/
init.go
75 lines (61 loc) · 1.78 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
package http
import (
"github.com/roadrunner-server/http/v4/common"
bundledMw "github.com/roadrunner-server/http/v4/middleware"
"github.com/roadrunner-server/http/v4/servers/fcgi"
httpServer "github.com/roadrunner-server/http/v4/servers/http"
httpsServer "github.com/roadrunner-server/http/v4/servers/https"
)
// ------- PRIVATE ---------
func (p *Plugin) initServers() error {
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 (p *Plugin) applyBundledMiddleware() {
// apply max_req_size and logger middleware
for i := 0; i < len(p.servers); i++ {
serv := p.servers[i].Server()
serv.Handler = bundledMw.MaxRequestSize(serv.Handler, p.cfg.MaxRequestSize*MB)
serv.Handler = bundledMw.NewLogMiddleware(serv.Handler, p.cfg.AccessLogs, p.log)
}
}
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
}