Parcourir la source

code cleanup

pull/294/head
Stefan Benten il y a 4 ans
Parent
révision
97632e4c0e
2 fichiers modifiés avec 4 ajouts et 34 suppressions
  1. +2
    -2
      server/clamav.go
  2. +2
    -32
      server/utils/utils.go

+ 2
- 2
server/clamav.go Voir le fichier

@@ -34,7 +34,7 @@ import (
"net/http" "net/http"
"time" "time"


clamd "github.com/dutchcoders/go-clamd"
"github.com/dutchcoders/go-clamd"
"github.com/dutchcoders/transfer.sh/server/utils" "github.com/dutchcoders/transfer.sh/server/utils"
"github.com/gorilla/mux" "github.com/gorilla/mux"
) )
@@ -65,7 +65,7 @@ func (s *Server) scanHandler(w http.ResponseWriter, r *http.Request) {


select { select {
case s := <-response: 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): case <-time.After(time.Second * 60):
abort <- true abort <- true
} }


+ 2
- 32
server/utils/utils.go Voir le fichier

@@ -30,7 +30,6 @@ import (
"math" "math"
"net" "net"
"net/http" "net/http"
"net/mail"
"net/url" "net/url"
"os" "os"
"path" "path"
@@ -287,43 +286,14 @@ func IpAddrFromRemoteAddr(s string) string {
return s[:idx] 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 { func AcceptsHTML(hdr http.Header) bool {
actual := header.ParseAccept(hdr, "Accept") actual := header.ParseAccept(hdr, "Accept")


for _, s := range actual { for _, s := range actual {
if s.Value == "text/html" { if s.Value == "text/html" {
return (true)
return true
} }
} }


return (false)
return false
} }

Chargement…
Annuler
Enregistrer