Stefan Benten 4 лет назад
Родитель
Сommit
97632e4c0e
2 измененных файлов: 4 добавлений и 34 удалений
  1. +2
    -2
      server/clamav.go
  2. +2
    -32
      server/utils/utils.go

+ 2
- 2
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
}


+ 2
- 32
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
}

Загрузка…
Отмена
Сохранить