mirror of
https://github.com/SagerNet/sing-box.git
synced 2025-06-08 11:44:13 +08:00
Fix http.FileServer short write
This commit is contained in:
parent
28f4fff423
commit
7c6a81ed13
@ -131,7 +131,7 @@ func NewServer(ctx context.Context, logFactory log.ObservableFactory, options op
|
||||
s.externalUI = filemanager.BasePath(ctx, os.ExpandEnv(options.ExternalUI))
|
||||
chiRouter.Group(func(r chi.Router) {
|
||||
r.Get("/ui", http.RedirectHandler("/ui/", http.StatusMovedPermanently).ServeHTTP)
|
||||
r.Handle("/ui/*", http.StripPrefix("/ui/", http.FileServer(http.Dir(s.externalUI))))
|
||||
r.Handle("/ui/*", http.StripPrefix("/ui/", http.FileServer(Dir(s.externalUI))))
|
||||
})
|
||||
}
|
||||
return s, nil
|
||||
|
18
experimental/clashapi/server_fs.go
Normal file
18
experimental/clashapi/server_fs.go
Normal file
@ -0,0 +1,18 @@
|
||||
package clashapi
|
||||
|
||||
import "net/http"
|
||||
|
||||
type Dir http.Dir
|
||||
|
||||
func (d Dir) Open(name string) (http.File, error) {
|
||||
file, err := http.Dir(d).Open(name)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &fileWrapper{file}, nil
|
||||
}
|
||||
|
||||
// workaround for #2345 #2596
|
||||
type fileWrapper struct {
|
||||
http.File
|
||||
}
|
@ -43,7 +43,6 @@ func (s *Server) downloadExternalUI() error {
|
||||
} else {
|
||||
downloadURL = "https://github.com/MetaCubeX/Yacd-meta/archive/gh-pages.zip"
|
||||
}
|
||||
s.logger.Info("downloading external ui")
|
||||
var detour adapter.Outbound
|
||||
if s.externalUIDownloadDetour != "" {
|
||||
outbound, loaded := s.outbound.Outbound(s.externalUIDownloadDetour)
|
||||
@ -55,6 +54,7 @@ func (s *Server) downloadExternalUI() error {
|
||||
outbound := s.outbound.Default()
|
||||
detour = outbound
|
||||
}
|
||||
s.logger.Info("downloading external ui using outbound/", detour.Type(), "[", detour.Tag(), "]")
|
||||
httpClient := &http.Client{
|
||||
Transport: &http.Transport{
|
||||
ForceAttemptHTTP2: true,
|
||||
|
Loading…
x
Reference in New Issue
Block a user