server: fix truncating last IP address digit

This commit is contained in:
mappu 2017-10-08 15:25:01 +13:00
parent 74212353ec
commit d9e4c9b420
2 changed files with 5 additions and 3 deletions

View File

@ -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 {

View File

@ -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)