diff --git a/cmd/bucket-handlers.go b/cmd/bucket-handlers.go index 22553a90b..fa44013d9 100644 --- a/cmd/bucket-handlers.go +++ b/cmd/bucket-handlers.go @@ -22,7 +22,6 @@ import ( "encoding/xml" "fmt" "io" - "net" "net/http" "net/url" "path" @@ -371,13 +370,6 @@ func (api objectAPIHandlers) DeleteMultipleObjectsHandler(w http.ResponseWriter, // Write success response. writeSuccessResponseXML(w, encodedSuccessResponse) - // Get host and port from Request.RemoteAddr failing which - // fill them with empty strings. - host, port, err := net.SplitHostPort(handlers.GetSourceIP(r)) - if err != nil { - host, port = "", "" - } - // Notify deleted event for objects. for _, dobj := range deletedObjects { sendEvent(eventArgs{ @@ -389,8 +381,7 @@ func (api objectAPIHandlers) DeleteMultipleObjectsHandler(w http.ResponseWriter, ReqParams: extractReqParams(r), RespElements: extractRespElements(w), UserAgent: r.UserAgent(), - Host: host, - Port: port, + Host: handlers.GetSourceIP(r), }) } } @@ -681,12 +672,6 @@ func (api objectAPIHandlers) PostPolicyBucketHandler(w http.ResponseWriter, r *h w.Header().Set("ETag", `"`+objInfo.ETag+`"`) w.Header().Set("Location", location) - // Get host and port from Request.RemoteAddr. - host, port, err := net.SplitHostPort(handlers.GetSourceIP(r)) - if err != nil { - host, port = "", "" - } - // Notify object created event. defer sendEvent(eventArgs{ EventName: event.ObjectCreatedPost, @@ -695,8 +680,7 @@ func (api objectAPIHandlers) PostPolicyBucketHandler(w http.ResponseWriter, r *h ReqParams: extractReqParams(r), RespElements: extractRespElements(w), UserAgent: r.UserAgent(), - Host: host, - Port: port, + Host: handlers.GetSourceIP(r), }) if successRedirect != "" { diff --git a/cmd/notification.go b/cmd/notification.go index 0a72874bf..588272cb5 100644 --- a/cmd/notification.go +++ b/cmd/notification.go @@ -839,7 +839,6 @@ type eventArgs struct { ReqParams map[string]string RespElements map[string]string Host string - Port string UserAgent string } @@ -894,7 +893,6 @@ func (args eventArgs) ToEvent() event.Event { }, Source: event.Source{ Host: args.Host, - Port: args.Port, UserAgent: args.UserAgent, }, } diff --git a/cmd/object-handlers-common.go b/cmd/object-handlers-common.go index e514e337d..2ccea8d1d 100644 --- a/cmd/object-handlers-common.go +++ b/cmd/object-handlers-common.go @@ -18,7 +18,6 @@ package cmd import ( "context" - "net" "net/http" "strings" "time" @@ -253,9 +252,6 @@ func deleteObject(ctx context.Context, obj ObjectLayer, cache CacheObjectLayer, return err } - // Get host and port from Request.RemoteAddr. - host, port, _ := net.SplitHostPort(handlers.GetSourceIP(r)) - // Notify object deleted event. sendEvent(eventArgs{ EventName: event.ObjectRemovedDelete, @@ -265,8 +261,7 @@ func deleteObject(ctx context.Context, obj ObjectLayer, cache CacheObjectLayer, }, ReqParams: extractReqParams(r), UserAgent: r.UserAgent(), - Host: host, - Port: port, + Host: handlers.GetSourceIP(r), }) return nil diff --git a/cmd/object-handlers.go b/cmd/object-handlers.go index f59515180..c497dada6 100644 --- a/cmd/object-handlers.go +++ b/cmd/object-handlers.go @@ -24,7 +24,6 @@ import ( "encoding/xml" "io" goioutil "io/ioutil" - "net" "net/http" "net/url" "sort" @@ -221,12 +220,6 @@ func (api objectAPIHandlers) SelectObjectContentHandler(w http.ResponseWriter, r s3Select.Evaluate(w) s3Select.Close() - // Get host and port from Request.RemoteAddr. - host, port, err := net.SplitHostPort(handlers.GetSourceIP(r)) - if err != nil { - host, port = "", "" - } - // Notify object accessed via a GET request. sendEvent(eventArgs{ EventName: event.ObjectAccessedGet, @@ -235,8 +228,7 @@ func (api objectAPIHandlers) SelectObjectContentHandler(w http.ResponseWriter, r ReqParams: extractReqParams(r), RespElements: extractRespElements(w), UserAgent: r.UserAgent(), - Host: host, - Port: port, + Host: handlers.GetSourceIP(r), }) } @@ -402,12 +394,6 @@ func (api objectAPIHandlers) GetObjectHandler(w http.ResponseWriter, r *http.Req } } - // Get host and port from Request.RemoteAddr. - host, port, err := net.SplitHostPort(handlers.GetSourceIP(r)) - if err != nil { - host, port = "", "" - } - // Notify object accessed via a GET request. sendEvent(eventArgs{ EventName: event.ObjectAccessedGet, @@ -416,8 +402,7 @@ func (api objectAPIHandlers) GetObjectHandler(w http.ResponseWriter, r *http.Req ReqParams: extractReqParams(r), RespElements: extractRespElements(w), UserAgent: r.UserAgent(), - Host: host, - Port: port, + Host: handlers.GetSourceIP(r), }) } @@ -562,11 +547,6 @@ func (api objectAPIHandlers) HeadObjectHandler(w http.ResponseWriter, r *http.Re w.WriteHeader(http.StatusOK) } - // Get host and port from Request.RemoteAddr. - host, port, err := net.SplitHostPort(handlers.GetSourceIP(r)) - if err != nil { - host, port = "", "" - } // Notify object accessed via a HEAD request. sendEvent(eventArgs{ EventName: event.ObjectAccessedHead, @@ -575,8 +555,7 @@ func (api objectAPIHandlers) HeadObjectHandler(w http.ResponseWriter, r *http.Re ReqParams: extractReqParams(r), RespElements: extractRespElements(w), UserAgent: r.UserAgent(), - Host: host, - Port: port, + Host: handlers.GetSourceIP(r), }) } @@ -1032,12 +1011,6 @@ func (api objectAPIHandlers) CopyObjectHandler(w http.ResponseWriter, r *http.Re // Write success response. writeSuccessResponseXML(w, encodedSuccessResponse) - // Get host and port from Request.RemoteAddr. - host, port, err := net.SplitHostPort(handlers.GetSourceIP(r)) - if err != nil { - host, port = "", "" - } - if objInfo.IsCompressed() { objInfo.Size = actualSize } @@ -1050,8 +1023,7 @@ func (api objectAPIHandlers) CopyObjectHandler(w http.ResponseWriter, r *http.Re ReqParams: extractReqParams(r), RespElements: extractRespElements(w), UserAgent: r.UserAgent(), - Host: host, - Port: port, + Host: handlers.GetSourceIP(r), }) } @@ -1303,12 +1275,6 @@ func (api objectAPIHandlers) PutObjectHandler(w http.ResponseWriter, r *http.Req writeSuccessResponseHeadersOnly(w) - // Get host and port from Request.RemoteAddr. - host, port, err := net.SplitHostPort(handlers.GetSourceIP(r)) - if err != nil { - host, port = "", "" - } - // Notify object created event. sendEvent(eventArgs{ EventName: event.ObjectCreatedPut, @@ -1317,8 +1283,7 @@ func (api objectAPIHandlers) PutObjectHandler(w http.ResponseWriter, r *http.Req ReqParams: extractReqParams(r), RespElements: extractRespElements(w), UserAgent: r.UserAgent(), - Host: host, - Port: port, + Host: handlers.GetSourceIP(r), }) } @@ -2345,16 +2310,12 @@ func (api objectAPIHandlers) CompleteMultipartUploadHandler(w http.ResponseWrite writeSuccessResponseXML(w, encodedSuccessResponse) // Get host and port from Request.RemoteAddr. - host, port, err := net.SplitHostPort(handlers.GetSourceIP(r)) - if err != nil { - host, port = "", "" - } - if objectAPI.IsEncryptionSupported() { if crypto.IsEncrypted(objInfo.UserDefined) { objInfo.Size, _ = objInfo.DecryptedSize() } } + // Notify object created event. sendEvent(eventArgs{ EventName: event.ObjectCreatedCompleteMultipartUpload, @@ -2363,8 +2324,7 @@ func (api objectAPIHandlers) CompleteMultipartUploadHandler(w http.ResponseWrite ReqParams: extractReqParams(r), RespElements: extractRespElements(w), UserAgent: r.UserAgent(), - Host: host, - Port: port, + Host: handlers.GetSourceIP(r), }) } diff --git a/cmd/web-handlers.go b/cmd/web-handlers.go index 267e8da4c..f04e49729 100644 --- a/cmd/web-handlers.go +++ b/cmd/web-handlers.go @@ -22,7 +22,6 @@ import ( "encoding/json" "fmt" "io" - "net" "net/http" "net/url" "os" @@ -983,12 +982,6 @@ func (web *webAPIHandlers) Upload(w http.ResponseWriter, r *http.Request) { } } - // Get host and port from Request.RemoteAddr. - host, port, err := net.SplitHostPort(handlers.GetSourceIP(r)) - if err != nil { - host, port = "", "" - } - // Notify object created event. sendEvent(eventArgs{ EventName: event.ObjectCreatedPut, @@ -997,8 +990,7 @@ func (web *webAPIHandlers) Upload(w http.ResponseWriter, r *http.Request) { ReqParams: extractReqParams(r), RespElements: extractRespElements(w), UserAgent: r.UserAgent(), - Host: host, - Port: port, + Host: handlers.GetSourceIP(r), }) } @@ -1116,12 +1108,6 @@ func (web *webAPIHandlers) Download(w http.ResponseWriter, r *http.Request) { } } - // Get host and port from Request.RemoteAddr. - host, port, err := net.SplitHostPort(handlers.GetSourceIP(r)) - if err != nil { - host, port = "", "" - } - // Notify object accessed via a GET request. sendEvent(eventArgs{ EventName: event.ObjectAccessedGet, @@ -1130,8 +1116,7 @@ func (web *webAPIHandlers) Download(w http.ResponseWriter, r *http.Request) { ReqParams: extractReqParams(r), RespElements: extractRespElements(w), UserAgent: r.UserAgent(), - Host: host, - Port: port, + Host: handlers.GetSourceIP(r), }) } @@ -1146,11 +1131,7 @@ type DownloadZipArgs struct { // Takes a list of objects and creates a zip file that sent as the response body. func (web *webAPIHandlers) DownloadZip(w http.ResponseWriter, r *http.Request) { - // Get host and port from Request.RemoteAddr. - host, port, err := net.SplitHostPort(handlers.GetSourceIP(r)) - if err != nil { - host, port = "", "" - } + host := handlers.GetSourceIP(r) ctx := newContext(r, w, "WebDownloadZip") defer logger.AuditLog(w, r, "WebDownloadZip", mustGetClaimsFromToken(r)) @@ -1335,7 +1316,6 @@ func (web *webAPIHandlers) DownloadZip(w http.ResponseWriter, r *http.Request) { RespElements: extractRespElements(w), UserAgent: r.UserAgent(), Host: host, - Port: port, }) return nil