api: SourceInfo should be populated in GET/HEAD notification. (#4073)

Refer https://github.com/minio/mc/issues/2073
master
Harshavardhana 8 years ago committed by GitHub
parent 6b4f368dfe
commit 0497d5c342
  1. 21
      cmd/object-handlers.go

@ -138,6 +138,7 @@ func (api objectAPIHandlers) GetObjectHandler(w http.ResponseWriter, r *http.Req
startOffset = hrange.offsetBegin startOffset = hrange.offsetBegin
length = hrange.getLength() length = hrange.getLength()
} }
// Indicates if any data was written to the http.ResponseWriter // Indicates if any data was written to the http.ResponseWriter
dataWritten := false dataWritten := false
// io.Writer type which keeps track if any data was written. // io.Writer type which keeps track if any data was written.
@ -156,7 +157,7 @@ func (api objectAPIHandlers) GetObjectHandler(w http.ResponseWriter, r *http.Req
}) })
// Reads the object at startOffset and writes to mw. // Reads the object at startOffset and writes to mw.
if err := objectAPI.GetObject(bucket, object, startOffset, length, writer); err != nil { if err = objectAPI.GetObject(bucket, object, startOffset, length, writer); err != nil {
errorIf(err, "Unable to write to client.") errorIf(err, "Unable to write to client.")
if !dataWritten { if !dataWritten {
// Error response only if no data has been written to client yet. i.e if // Error response only if no data has been written to client yet. i.e if
@ -174,12 +175,21 @@ func (api objectAPIHandlers) GetObjectHandler(w http.ResponseWriter, r *http.Req
writer.Write(nil) writer.Write(nil)
} }
// Get host and port from Request.RemoteAddr.
host, port, err := net.SplitHostPort(r.RemoteAddr)
if err != nil {
host, port = "", ""
}
// Notify object accessed via a GET request. // Notify object accessed via a GET request.
eventNotify(eventData{ eventNotify(eventData{
Type: ObjectAccessedGet, Type: ObjectAccessedGet,
Bucket: bucket, Bucket: bucket,
ObjInfo: objInfo, ObjInfo: objInfo,
ReqParams: extractReqParams(r), ReqParams: extractReqParams(r),
UserAgent: r.UserAgent(),
Host: host,
Port: port,
}) })
} }
@ -230,12 +240,21 @@ func (api objectAPIHandlers) HeadObjectHandler(w http.ResponseWriter, r *http.Re
// Successful response. // Successful response.
w.WriteHeader(http.StatusOK) w.WriteHeader(http.StatusOK)
// Get host and port from Request.RemoteAddr.
host, port, err := net.SplitHostPort(r.RemoteAddr)
if err != nil {
host, port = "", ""
}
// Notify object accessed via a HEAD request. // Notify object accessed via a HEAD request.
eventNotify(eventData{ eventNotify(eventData{
Type: ObjectAccessedHead, Type: ObjectAccessedHead,
Bucket: bucket, Bucket: bucket,
ObjInfo: objInfo, ObjInfo: objInfo,
ReqParams: extractReqParams(r), ReqParams: extractReqParams(r),
UserAgent: r.UserAgent(),
Host: host,
Port: port,
}) })
} }

Loading…
Cancel
Save