Browse Source

Add -nodirectagents flag

to disable serving files directly for wget/curl user agents
pull/145/head
Thor77 6 years ago
parent
commit
53e6ecf166
  1. 2
      display.go
  2. 3
      server.go

2
display.go

@ -22,7 +22,7 @@ const maxDisplayFileSizeBytes = 1024 * 512
var cliUserAgentRe = regexp.MustCompile("(?i)(lib)?curl|wget")
func fileDisplayHandler(c web.C, w http.ResponseWriter, r *http.Request) {
if cliUserAgentRe.MatchString(r.Header.Get("User-Agent")) {
if !Config.noDirectAgents && cliUserAgentRe.MatchString(r.Header.Get("User-Agent")) {
fileServeHandler(c, w, r)
return
}

3
server.go

@ -58,6 +58,7 @@ var Config struct {
remoteAuthFile string
addHeaders headerList
googleShorterAPIKey string
noDirectAgents bool
}
var Templates = make(map[string]*pongo2.Template)
@ -243,6 +244,8 @@ func main() {
"Add an arbitrary header to the response. This option can be used multiple times.")
flag.StringVar(&Config.googleShorterAPIKey, "googleapikey", "",
"API Key for Google's URL Shortener.")
flag.BoolVar(&Config.noDirectAgents, "nodirectagents", false,
"disable serving files directly for wget/curl user agents")
iniflags.Parse()

Loading…
Cancel
Save