Eliminate duplicate code, make use of readHeaderTimeout const
This commit is contained in:
@@ -46,8 +46,8 @@ func NewServer(configPath string) (*http.Server, error) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// Both username AND password must match. Fuck De Morgan and his bullshit laws - we explicitly require
|
// Both username AND password must match. Explicitly require that the whole condition
|
||||||
// that the whole condition fails. That *is* the point.
|
// fails when either is incorrect, per the authentication design.
|
||||||
//nolint:staticcheck // QF1001: De Morgan's law is irrelevant here.
|
//nolint:staticcheck // QF1001: De Morgan's law is irrelevant here.
|
||||||
if !(username == C.User && password == C.Password) {
|
if !(username == C.User && password == C.Password) {
|
||||||
w.Header().Set("WWW-Authenticate", `Basic realm="restricted", charset="UTF-8"`)
|
w.Header().Set("WWW-Authenticate", `Basic realm="restricted", charset="UTF-8"`)
|
||||||
@@ -128,19 +128,8 @@ func NewServer(configPath string) (*http.Server, error) {
|
|||||||
log.Infof("Backup completed: client=%s user=%s files=%d bytes=%d duration=%s", clientIP, username, len(files), bytesWritten, duration)
|
log.Infof("Backup completed: client=%s user=%s files=%d bytes=%d duration=%s", clientIP, username, len(files), bytesWritten, duration)
|
||||||
})
|
})
|
||||||
|
|
||||||
// Decision about which mode (http or https) to run made in cmd/backer/main.go, where we run server.ListenAndServe()
|
// HTTP mode if nohttps is enabled in config.
|
||||||
// or server.ListenAndServeTLS() depending on value of C.NoHTTPS.
|
// HTTPS mode if nohttps is disabled in config.
|
||||||
if C.NoHTTPS {
|
|
||||||
return &http.Server{
|
|
||||||
Addr: fmt.Sprintf("%s:%d", C.Address, C.Port),
|
|
||||||
Handler: withServerHeader(mux),
|
|
||||||
ReadHeaderTimeout: readHeaderTimeout,
|
|
||||||
WriteTimeout: time.Duration(C.BackupTimeout) * time.Minute,
|
|
||||||
}, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// Decision about which mode (http or https) to run made in cmd/backer/main.go, where we run server.ListenAndServe()
|
|
||||||
// or server.ListenAndServeTLS() depending on value of C.NoHTTPS.
|
|
||||||
if C.NoHTTPS {
|
if C.NoHTTPS {
|
||||||
return &http.Server{
|
return &http.Server{
|
||||||
Addr: fmt.Sprintf("%s:%d", C.Address, C.Port),
|
Addr: fmt.Sprintf("%s:%d", C.Address, C.Port),
|
||||||
@@ -153,7 +142,7 @@ func NewServer(configPath string) (*http.Server, error) {
|
|||||||
return &http.Server{
|
return &http.Server{
|
||||||
Addr: fmt.Sprintf("%s:%d", C.Address, C.Port),
|
Addr: fmt.Sprintf("%s:%d", C.Address, C.Port),
|
||||||
Handler: withServerHeader(mux),
|
Handler: withServerHeader(mux),
|
||||||
ReadHeaderTimeout: 5 * time.Second,
|
ReadHeaderTimeout: readHeaderTimeout,
|
||||||
WriteTimeout: time.Duration(C.BackupTimeout) * time.Minute,
|
WriteTimeout: time.Duration(C.BackupTimeout) * time.Minute,
|
||||||
TLSConfig: &tls.Config{
|
TLSConfig: &tls.Config{
|
||||||
MinVersion: tls.VersionTLS13,
|
MinVersion: tls.VersionTLS13,
|
||||||
|
|||||||
Reference in New Issue
Block a user