From d9e4c9b420acd46cc4d0dffa632888871f1e426b Mon Sep 17 00:00:00 2001 From: mappu Date: Sun, 8 Oct 2017 15:25:01 +1300 Subject: [PATCH] server: fix truncating last IP address digit --- Server.go | 4 ++++ upload.go | 4 +--- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/Server.go b/Server.go index 5f60e53..88ff2ab 100644 --- a/Server.go +++ b/Server.go @@ -116,6 +116,10 @@ func (this *Server) handleAbout(w http.ResponseWriter) { this.serveJsonObject(w, this.opts.ServerPublicProperties) } +func remoteIP(r *http.Request) string { + return strings.TrimRight(strings.TrimRight(r.RemoteAddr, "0123456789"), ":") +} + func (this *Server) ServeHTTP(w http.ResponseWriter, r *http.Request) { w.Header().Set(`Server`, SERVER_HEADER) if this.opts.MaxUploadBytes > 0 { diff --git a/upload.go b/upload.go index 3021c73..a85df15 100644 --- a/upload.go +++ b/upload.go @@ -31,8 +31,6 @@ func (this *Server) handleUpload(w http.ResponseWriter, r *http.Request) { return } - remoteIP := strings.TrimRight(r.RemoteAddr, "0123456789:") - ret := make([]string, 0, len(r.MultipartForm.File["f"])) for _, fhs := range r.MultipartForm.File["f"] { @@ -43,7 +41,7 @@ func (this *Server) handleUpload(w http.ResponseWriter, r *http.Request) { return } - path, err := this.handleUploadFile(f, fhs, remoteIP) + path, err := this.handleUploadFile(f, fhs, remoteIP(r)) if err != nil { log.Printf("%s Upload failed: %s\n", r.RemoteAddr, err.Error()) http.Error(w, "Upload failed", 500)