From 8362a2ee2dd55abbb6a6d5bd1e2ac9b0a6eaf895 Mon Sep 17 00:00:00 2001 From: Weidi Deng Date: Tue, 29 Dec 2020 10:42:33 +0800 Subject: [PATCH] use global commandline arguments to disable type detection by header --- files/utils.go | 2 +- http/data.go | 10 +++------- rules/rules.go | 2 +- settings/settings.go | 23 ++++++++++++----------- 4 files changed, 17 insertions(+), 20 deletions(-) diff --git a/files/utils.go b/files/utils.go index bcaa13f1..f4b0365d 100644 --- a/files/utils.go +++ b/files/utils.go @@ -5,7 +5,7 @@ import ( "unicode/utf8" ) -func isBinary(content []byte, _ int) bool { +func isBinary(content []byte) bool { maybeStr := string(content) runeCnt := utf8.RuneCount(content) runeIndex := 0 diff --git a/http/data.go b/http/data.go index d419eed9..98120dcc 100644 --- a/http/data.go +++ b/http/data.go @@ -47,13 +47,9 @@ func (d *data) Check(path string) bool { return allow } -func (d *data) IsTypeDetectDisabled(path string) bool { - for _, rule := range d.user.DisableTypeDetections { - if rule.Matches(path) { - return true - } - } - return false +// ReadHeader implements rules.ReadHeader. +func (d *data) ReadHeader() bool { + return d.server.TypeDetectionByHeader } func handle(fn handleFunc, prefix string, store *storage.Storage, server *settings.Server) http.Handler { diff --git a/rules/rules.go b/rules/rules.go index 494f6a0b..41391926 100644 --- a/rules/rules.go +++ b/rules/rules.go @@ -9,7 +9,7 @@ import ( // Checker is a Rules checker. type Checker interface { Check(path string) bool - IsTypeDetectDisabled(path string) bool + ReadHeader() bool } // Rule is a allow/disallow rule. diff --git a/settings/settings.go b/settings/settings.go index 6bf4c4db..0f8616d2 100644 --- a/settings/settings.go +++ b/settings/settings.go @@ -30,17 +30,18 @@ func (s *Settings) GetRules() []rules.Rule { // Server specific settings. type Server struct { - Root string `json:"root"` - BaseURL string `json:"baseURL"` - Socket string `json:"socket"` - TLSKey string `json:"tlsKey"` - TLSCert string `json:"tlsCert"` - Port string `json:"port"` - Address string `json:"address"` - Log string `json:"log"` - EnableThumbnails bool `json:"enableThumbnails"` - ResizePreview bool `json:"resizePreview"` - EnableExec bool `json:"enableExec"` + Root string `json:"root"` + BaseURL string `json:"baseURL"` + Socket string `json:"socket"` + TLSKey string `json:"tlsKey"` + TLSCert string `json:"tlsCert"` + Port string `json:"port"` + Address string `json:"address"` + Log string `json:"log"` + EnableThumbnails bool `json:"enableThumbnails"` + ResizePreview bool `json:"resizePreview"` + EnableExec bool `json:"enableExec"` + TypeDetectionByHeader bool `json:"typeDetectionByHeader"` } // Clean cleans any variables that might need cleaning.