From 97632e4c0e61076bd7eacc5390584e7c3e964057 Mon Sep 17 00:00:00 2001 From: Stefan Benten Date: Sun, 29 Mar 2020 12:51:35 +0200 Subject: [PATCH] code cleanup --- server/clamav.go | 4 ++-- server/utils/utils.go | 34 ++-------------------------------- 2 files changed, 4 insertions(+), 34 deletions(-) diff --git a/server/clamav.go b/server/clamav.go index 8c24371..d20ff41 100644 --- a/server/clamav.go +++ b/server/clamav.go @@ -34,7 +34,7 @@ import ( "net/http" "time" - clamd "github.com/dutchcoders/go-clamd" + "github.com/dutchcoders/go-clamd" "github.com/dutchcoders/transfer.sh/server/utils" "github.com/gorilla/mux" ) @@ -65,7 +65,7 @@ func (s *Server) scanHandler(w http.ResponseWriter, r *http.Request) { select { case s := <-response: - w.Write([]byte(fmt.Sprintf("%v\n", s.Status))) + _, _ = w.Write([]byte(fmt.Sprintf("%v\n", s.Status))) case <-time.After(time.Second * 60): abort <- true } diff --git a/server/utils/utils.go b/server/utils/utils.go index 4894d6e..9be4056 100644 --- a/server/utils/utils.go +++ b/server/utils/utils.go @@ -30,7 +30,6 @@ import ( "math" "net" "net/http" - "net/mail" "net/url" "os" "path" @@ -287,43 +286,14 @@ func IpAddrFromRemoteAddr(s string) string { return s[:idx] } -func GetIPAddress(r *http.Request) string { - hdr := r.Header - hdrRealIP := hdr.Get("X-Real-Ip") - hdrForwardedFor := hdr.Get("X-Forwarded-For") - if hdrRealIP == "" && hdrForwardedFor == "" { - return IpAddrFromRemoteAddr(r.RemoteAddr) - } - if hdrForwardedFor != "" { - // X-Forwarded-For is potentially a list of addresses separated with "," - parts := strings.Split(hdrForwardedFor, ",") - for i, p := range parts { - parts[i] = strings.TrimSpace(p) - } - - // TODO: should return first non-local address - return parts[0] - } - return hdrRealIP -} - -func encodeRFC2047(s string) string { - // use mail's rfc2047 to encode any string - addr := mail.Address{ - Name: s, - Address: "", - } - return strings.Trim(addr.String(), " <>") -} - func AcceptsHTML(hdr http.Header) bool { actual := header.ParseAccept(hdr, "Accept") for _, s := range actual { if s.Value == "text/html" { - return (true) + return true } } - return (false) + return false }