fix application bug
This commit is contained in:
3
vendor/github.com/mholt/caddy/caddyhttp/httpserver/plugin.go
generated
vendored
3
vendor/github.com/mholt/caddy/caddyhttp/httpserver/plugin.go
generated
vendored
@@ -234,7 +234,7 @@ func (h *httpContext) MakeServers() ([]caddy.Server, error) {
|
||||
// trusted CA (obviously not a perfect heuristic)
|
||||
var looksLikeProductionCA bool
|
||||
for _, publicCAEndpoint := range caddytls.KnownACMECAs {
|
||||
if strings.Contains(certmagic.CA, publicCAEndpoint) {
|
||||
if strings.Contains(certmagic.Default.CA, publicCAEndpoint) {
|
||||
looksLikeProductionCA = true
|
||||
break
|
||||
}
|
||||
@@ -685,6 +685,7 @@ var directives = []string{
|
||||
"gopkg", // github.com/zikes/gopkg
|
||||
"restic", // github.com/restic/caddy
|
||||
"wkd", // github.com/emersion/caddy-wkd
|
||||
"dyndns", // github.com/linkonoid/caddy-dyndns
|
||||
}
|
||||
|
||||
const (
|
||||
|
||||
42
vendor/github.com/mholt/caddy/caddyhttp/httpserver/server.go
generated
vendored
42
vendor/github.com/mholt/caddy/caddyhttp/httpserver/server.go
generated
vendored
@@ -29,7 +29,6 @@ import (
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/lucas-clemente/quic-go/h2quic"
|
||||
@@ -43,8 +42,6 @@ import (
|
||||
type Server struct {
|
||||
Server *http.Server
|
||||
quicServer *h2quic.Server
|
||||
listener net.Listener
|
||||
listenerMu sync.Mutex
|
||||
sites []*SiteConfig
|
||||
connTimeout time.Duration // max time to wait for a connection before force stop
|
||||
tlsGovChan chan struct{} // close to stop the TLS maintenance goroutine
|
||||
@@ -237,7 +234,9 @@ func makeHTTPServerWithTimeouts(addr string, group []*SiteConfig) *http.Server {
|
||||
|
||||
func (s *Server) wrapWithSvcHeaders(previousHandler http.Handler) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
s.quicServer.SetQuicHeaders(w.Header())
|
||||
if err := s.quicServer.SetQuicHeaders(w.Header()); err != nil {
|
||||
log.Println("[Error] failed to set proper headers for QUIC: ", err)
|
||||
}
|
||||
previousHandler.ServeHTTP(w, r)
|
||||
}
|
||||
}
|
||||
@@ -246,7 +245,7 @@ func (s *Server) wrapWithSvcHeaders(previousHandler http.Handler) http.HandlerFu
|
||||
// used to serve requests.
|
||||
func (s *Server) Listen() (net.Listener, error) {
|
||||
if s.Server == nil {
|
||||
return nil, fmt.Errorf("Server field is nil")
|
||||
return nil, fmt.Errorf("server field is nil")
|
||||
}
|
||||
|
||||
ln, err := net.Listen("tcp", s.Server.Addr)
|
||||
@@ -310,10 +309,6 @@ func (s *Server) ListenPacket() (net.PacketConn, error) {
|
||||
|
||||
// Serve serves requests on ln. It blocks until ln is closed.
|
||||
func (s *Server) Serve(ln net.Listener) error {
|
||||
s.listenerMu.Lock()
|
||||
s.listener = ln
|
||||
s.listenerMu.Unlock()
|
||||
|
||||
if s.Server.TLSConfig != nil {
|
||||
// Create TLS listener - note that we do not replace s.listener
|
||||
// with this TLS listener; tls.listener is unexported and does
|
||||
@@ -329,14 +324,19 @@ func (s *Server) Serve(ln net.Listener) error {
|
||||
s.tlsGovChan = caddytls.RotateSessionTicketKeys(s.Server.TLSConfig)
|
||||
}
|
||||
|
||||
defer func() {
|
||||
if s.quicServer != nil {
|
||||
if err := s.quicServer.Close(); err != nil {
|
||||
log.Println("[ERROR] failed to close QUIC server: ", err)
|
||||
}
|
||||
}
|
||||
}()
|
||||
|
||||
err := s.Server.Serve(ln)
|
||||
if err == http.ErrServerClosed {
|
||||
err = nil // not an error worth reporting since closing a server is intentional
|
||||
if err != nil && err != http.ErrServerClosed {
|
||||
return err
|
||||
}
|
||||
if s.quicServer != nil {
|
||||
s.quicServer.Close()
|
||||
}
|
||||
return err
|
||||
return nil
|
||||
}
|
||||
|
||||
// ServePacket serves QUIC requests on pc until it is closed.
|
||||
@@ -559,8 +559,12 @@ func (ln tcpKeepAliveListener) Accept() (c net.Conn, err error) {
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
tc.SetKeepAlive(true)
|
||||
tc.SetKeepAlivePeriod(3 * time.Minute)
|
||||
if err = tc.SetKeepAlive(true); err != nil {
|
||||
return
|
||||
}
|
||||
if err = tc.SetKeepAlivePeriod(3 * time.Minute); err != nil {
|
||||
return
|
||||
}
|
||||
return tc, nil
|
||||
}
|
||||
|
||||
@@ -598,7 +602,9 @@ func WriteTextResponse(w http.ResponseWriter, status int, body string) {
|
||||
w.Header().Set("Content-Type", "text/plain; charset=utf-8")
|
||||
w.Header().Set("X-Content-Type-Options", "nosniff")
|
||||
w.WriteHeader(status)
|
||||
w.Write([]byte(body))
|
||||
if _, err := w.Write([]byte(body)); err != nil {
|
||||
log.Println("[Error] failed to write body: ", err)
|
||||
}
|
||||
}
|
||||
|
||||
// SafePath joins siteRoot and reqPath and converts it to a path that can
|
||||
|
||||
5
vendor/github.com/mholt/caddy/caddyhttp/httpserver/tplcontext.go
generated
vendored
5
vendor/github.com/mholt/caddy/caddyhttp/httpserver/tplcontext.go
generated
vendored
@@ -19,6 +19,7 @@ import (
|
||||
"crypto/rand"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
mathrand "math/rand"
|
||||
"net"
|
||||
"net/http"
|
||||
@@ -420,7 +421,9 @@ func (c Context) RandomString(minLen, maxLen int) string {
|
||||
// secureRandomBytes returns a number of bytes using crypto/rand.
|
||||
secureRandomBytes := func(numBytes int) []byte {
|
||||
randomBytes := make([]byte, numBytes)
|
||||
rand.Read(randomBytes)
|
||||
if _, err := rand.Read(randomBytes); err != nil {
|
||||
log.Println("[ERROR] failed to read bytes: ", err)
|
||||
}
|
||||
return randomBytes
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user