-
Notifications
You must be signed in to change notification settings - Fork 1
/
server.go
46 lines (42 loc) · 1.42 KB
/
server.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
package web
import (
"crypto/tls"
"net/http"
)
// Применение настроек из конфигурации к стандартному веб серверу.
func (web *impl) makeServer(tlsConfig *tls.Config) (ret *http.Server, isTLS bool) {
const http11 = "http/1.1"
if web.handler == nil {
web.err = Errors().HandlerIsNotSet()
return
}
if web.cfg == nil {
web.err = Errors().NoConfiguration()
return
}
ret = &http.Server{
Handler: web.handler,
Addr: web.cfg.HostPort(),
DisableGeneralOptionsHandler: web.cfg.DisableGeneralOptionsHandler,
ReadTimeout: web.cfg.ReadTimeout,
ReadHeaderTimeout: web.cfg.ReadHeaderTimeout,
WriteTimeout: web.cfg.WriteTimeout,
IdleTimeout: web.cfg.IdleTimeout,
MaxHeaderBytes: web.cfg.MaxHeaderBytes,
TLSNextProto: make(map[string]func(*http.Server, *tls.Conn, http.Handler), 0),
}
if web.cfg.TLSPrivateKeyPEM == "" || web.cfg.TLSPublicKeyPEM == "" {
ret.TLSNextProto, isTLS = nil, false
return
}
// Конфигурация TLS по умолчанию.
if tlsConfig == nil {
tlsConfig, web.err = web.net.NewTLSConfigDefault(web.cfg.TLSPublicKeyPEM, web.cfg.TLSPrivateKeyPEM)
if web.err != nil {
return
}
}
tlsConfig.NextProtos = append(tlsConfig.NextProtos, http11)
ret.TLSConfig, isTLS = tlsConfig, true
return
}