Fast and extensible multi-platform HTTP/1-2-3 web server with automatic HTTPS
Mirrored from https://github.com/Slazee/caddy.git
Synced Nov 12, 04:30 UTC
fix: disable h3 for unix domain socket (#6769)
Hyeonggeun Oh committed
Jan 7, 2025 at 16:21 UTC
50778b55425d378f709599c0d424b0138af592f4
1 file changed
+27
-15
modules/caddyhttp/app.go
+27
-15
@@ -529,21 +529,6 @@ func (app *App) Start() error {
529
// enable TLS if there is a policy and if this is not the HTTP port
530
useTLS := len(srv.TLSConnPolicies) > 0 && int(listenAddr.StartPort+portOffset) != app.httpPort()
531
532
- // enable HTTP/3 if configured
533
- if h3ok && useTLS {
534
- app.logger.Info("enabling HTTP/3 listener", zap.String("addr", hostport))
535
- if err := srv.serveHTTP3(listenAddr.At(portOffset), tlsCfg); err != nil {
536
- return err
537
- }
538
- }
539
-
540
- if h3ok && !useTLS {
541
- // Can only serve h3 with TLS enabled
542
- app.logger.Warn("HTTP/3 skipped because it requires TLS",
543
- zap.String("network", listenAddr.Network),
544
- zap.String("addr", hostport))
545
- }
546
-
532
if h1ok || h2ok && useTLS || h2cok {
533
// create the listener for this socket
534
lnAny, err := listenAddr.Listen(app.ctx, portOffset, net.ListenConfig{KeepAlive: time.Duration(srv.KeepAliveInterval)})
@@ -614,6 +599,33 @@ func (app *App) Start() error {
599
zap.String("network", listenAddr.Network),
600
zap.String("addr", hostport))
601
}
602
+
603
+ if h3ok {
604
+ // Can't serve HTTP/3 on the same socket as HTTP/1 and 2 because it uses
605
+ // a different transport mechanism... which is fine, but the OS doesn't
606
+ // differentiate between a SOCK_STREAM file and a SOCK_DGRAM file; they
607
+ // are still one file on the system. So even though "unixpacket" and
608
+ // "unixgram" are different network types just as "tcp" and "udp" are,
609
+ // the OS will not let us use the same file as both STREAM and DGRAM.
610
+ if listenAddr.IsUnixNetwork() {
611
+ app.logger.Warn("HTTP/3 disabled because Unix can't multiplex STREAM and DGRAM on same socket",
612
+ zap.String("file", hostport))
613
+ continue
614
+ }
615
+
616
+ if useTLS {
617
+ // enable HTTP/3 if configured
618
+ app.logger.Info("enabling HTTP/3 listener", zap.String("addr", hostport))
619
+ if err := srv.serveHTTP3(listenAddr.At(portOffset), tlsCfg); err != nil {
620
+ return err
621
+ }
622
+ } else {
623
+ // Can only serve h3 with TLS enabled
624
+ app.logger.Warn("HTTP/3 skipped because it requires TLS",
625
+ zap.String("network", listenAddr.Network),
626
+ zap.String("addr", hostport))
627
+ }
628
+ }
629
}
630
}
631