From 85024eaeb2640c7cf73f36e56a3eb5cc57b7d10f Mon Sep 17 00:00:00 2001 From: Thor77 Date: Tue, 2 Oct 2018 21:36:44 +0200 Subject: [PATCH] Serve file directly for curl and wget user agents Fix #127 --- display.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/display.go b/display.go index c6d8470..ab9e601 100644 --- a/display.go +++ b/display.go @@ -4,6 +4,7 @@ import ( "encoding/json" "net/http" "path/filepath" + "regexp" "strconv" "strings" "time" @@ -18,7 +19,14 @@ import ( 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")) { + fileServeHandler(c, w, r) + return + } + fileName := c.URLParams["name"] err := checkFile(fileName)