Log incoming requests

This commit is contained in:
Melon 2023-08-12 15:58:41 +01:00
parent b84df84d51
commit ce12384c15
Signed by: melon
GPG Key ID: 6C9D970C50D26A25
2 changed files with 9 additions and 5 deletions

View File

@ -62,6 +62,7 @@ func domainManage(verify mjwt.Verifier, domains utils.DomainProvider) httprouter
// add domain with active state // add domain with active state
domains.Put(params.ByName("domain"), req.Method == http.MethodPut) domains.Put(params.ByName("domain"), req.Method == http.MethodPut)
domains.Compile() domains.Compile()
rw.WriteHeader(http.StatusAccepted)
}) })
} }

View File

@ -9,7 +9,6 @@ import (
"github.com/sethvargo/go-limiter/httplimit" "github.com/sethvargo/go-limiter/httplimit"
"github.com/sethvargo/go-limiter/memorystore" "github.com/sethvargo/go-limiter/memorystore"
"log" "log"
"net"
"net/http" "net/http"
"path" "path"
"time" "time"
@ -18,9 +17,16 @@ import (
// NewHttpsServer creates and runs a http server containing the public https // NewHttpsServer creates and runs a http server containing the public https
// endpoints for the reverse proxy. // endpoints for the reverse proxy.
func NewHttpsServer(conf *conf.Conf) *http.Server { func NewHttpsServer(conf *conf.Conf) *http.Server {
r := http.HandlerFunc(func(rw http.ResponseWriter, req *http.Request) {
log.Printf("[Debug] Request: %s - '%s' - '%s' - '%s' - len: %d\n", req.Method, req.URL.String(), req.RemoteAddr, req.Host, req.ContentLength)
conf.Router.ServeHTTP(rw, req)
})
favMiddleware := setupFaviconMiddleware(conf.Favicons, r)
rateLimiter := setupRateLimiter(conf.RateLimit, favMiddleware)
return &http.Server{ return &http.Server{
Addr: conf.HttpsListen, Addr: conf.HttpsListen,
Handler: setupRateLimiter(conf.RateLimit, setupFaviconMiddleware(conf.Favicons, conf.Router)), Handler: rateLimiter,
TLSConfig: &tls.Config{GetCertificate: func(info *tls.ClientHelloInfo) (*tls.Certificate, error) { TLSConfig: &tls.Config{GetCertificate: func(info *tls.ClientHelloInfo) (*tls.Certificate, error) {
// error out on invalid domains // error out on invalid domains
if !conf.Domains.IsValid(info.ServerName) { if !conf.Domains.IsValid(info.ServerName) {
@ -41,9 +47,6 @@ func NewHttpsServer(conf *conf.Conf) *http.Server {
WriteTimeout: 150 * time.Second, WriteTimeout: 150 * time.Second,
IdleTimeout: 150 * time.Second, IdleTimeout: 150 * time.Second,
MaxHeaderBytes: 4096000, MaxHeaderBytes: 4096000,
ConnState: func(conn net.Conn, state http.ConnState) {
fmt.Printf("[HTTPS] %s => %s: %s\n", conn.LocalAddr(), conn.RemoteAddr(), state.String())
},
} }
} }