44 "context"
55 "errors"
66 "fmt"
7- ftpserver "github.com/KirCute/ftpserverlib-pasvportmap"
8- "github.com/KirCute/sftpd-alist"
9- "github.com/alist-org/alist/v3/internal/fs"
107 "net"
118 "net/http"
129 "os"
@@ -16,14 +13,19 @@ import (
1613 "syscall"
1714 "time"
1815
16+ ftpserver "github.com/KirCute/ftpserverlib-pasvportmap"
17+ "github.com/KirCute/sftpd-alist"
1918 "github.com/alist-org/alist/v3/cmd/flags"
2019 "github.com/alist-org/alist/v3/internal/bootstrap"
2120 "github.com/alist-org/alist/v3/internal/conf"
21+ "github.com/alist-org/alist/v3/internal/fs"
2222 "github.com/alist-org/alist/v3/pkg/utils"
2323 "github.com/alist-org/alist/v3/server"
2424 "github.com/gin-gonic/gin"
2525 log "github.com/sirupsen/logrus"
2626 "github.com/spf13/cobra"
27+ "golang.org/x/net/http2"
28+ "golang.org/x/net/http2/h2c"
2729)
2830
2931// ServerCmd represents the server command
@@ -47,11 +49,15 @@ the address is defined in config file`,
4749 r := gin .New ()
4850 r .Use (gin .LoggerWithWriter (log .StandardLogger ().Out ), gin .RecoveryWithWriter (log .StandardLogger ().Out ))
4951 server .Init (r )
52+ var httpHandler http.Handler = r
53+ if conf .Conf .Scheme .EnableH2c {
54+ httpHandler = h2c .NewHandler (r , & http2.Server {})
55+ }
5056 var httpSrv , httpsSrv , unixSrv * http.Server
5157 if conf .Conf .Scheme .HttpPort != - 1 {
5258 httpBase := fmt .Sprintf ("%s:%d" , conf .Conf .Scheme .Address , conf .Conf .Scheme .HttpPort )
5359 utils .Log .Infof ("start HTTP server @ %s" , httpBase )
54- httpSrv = & http.Server {Addr : httpBase , Handler : r }
60+ httpSrv = & http.Server {Addr : httpBase , Handler : httpHandler }
5561 go func () {
5662 err := httpSrv .ListenAndServe ()
5763 if err != nil && ! errors .Is (err , http .ErrServerClosed ) {
@@ -72,7 +78,7 @@ the address is defined in config file`,
7278 }
7379 if conf .Conf .Scheme .UnixFile != "" {
7480 utils .Log .Infof ("start unix server @ %s" , conf .Conf .Scheme .UnixFile )
75- unixSrv = & http.Server {Handler : r }
81+ unixSrv = & http.Server {Handler : httpHandler }
7682 go func () {
7783 listener , err := net .Listen ("unix" , conf .Conf .Scheme .UnixFile )
7884 if err != nil {
0 commit comments