MCPcopy
hub / github.com/minio/minio-go / ToObjectInfo

Function ToObjectInfo

utils.go:275–434  ·  view source on GitHub ↗

ToObjectInfo converts http header values into ObjectInfo type, extracts metadata and fills in all the necessary fields in ObjectInfo.

(bucketName, objectName string, h http.Header)

Source from the content-addressed store, hash-verified

273// ToObjectInfo converts http header values into ObjectInfo type,
274// extracts metadata and fills in all the necessary fields in ObjectInfo.
275func ToObjectInfo(bucketName, objectName string, h http.Header) (ObjectInfo, error) {
276 var err error
277 // Trim off the odd double quotes from ETag in the beginning and end.
278 etag := trimEtag(h.Get("ETag"))
279
280 // Parse content length is exists
281 var size int64 = -1
282 contentLengthStr := h.Get("Content-Length")
283 if contentLengthStr != "" {
284 size, err = strconv.ParseInt(contentLengthStr, 10, 64)
285 if err != nil {
286 // Content-Length is not valid
287 return ObjectInfo{}, ErrorResponse{
288 Code: InternalError,
289 Message: fmt.Sprintf("Content-Length is not an integer, failed with %v", err),
290 BucketName: bucketName,
291 Key: objectName,
292 RequestID: h.Get("x-amz-request-id"),
293 HostID: h.Get("x-amz-id-2"),
294 Region: h.Get("x-amz-bucket-region"),
295 }
296 }
297 }
298
299 // Parse Last-Modified has http time format.
300 mtime, err := parseRFC7231Time(h.Get("Last-Modified"))
301 if err != nil {
302 return ObjectInfo{}, ErrorResponse{
303 Code: InternalError,
304 Message: fmt.Sprintf("Last-Modified time format is invalid, failed with %v", err),
305 BucketName: bucketName,
306 Key: objectName,
307 RequestID: h.Get("x-amz-request-id"),
308 HostID: h.Get("x-amz-id-2"),
309 Region: h.Get("x-amz-bucket-region"),
310 }
311 }
312 mtimeStr := h.Get("X-Minio-Source-Mtime")
313 if mtimeStr != "" {
314 mtime, err = time.Parse(time.RFC3339Nano, mtimeStr)
315 if err != nil {
316 return ObjectInfo{}, ErrorResponse{
317 Code: InternalError,
318 Message: fmt.Sprintf("X-Minio-Source-Mtime is not in supported format: %v", err),
319 BucketName: bucketName,
320 Key: objectName,
321 RequestID: h.Get("x-amz-request-id"),
322 HostID: h.Get("x-amz-id-2"),
323 Region: h.Get("x-amz-bucket-region"),
324 }
325 }
326 }
327
328 // Fetch content type if any present.
329 contentType := strings.TrimSpace(h.Get("Content-Type"))
330 if contentType == "" {
331 contentType = "application/octet-stream"
332 }

Callers 2

StatObjectMethod · 0.85
getObjectMethod · 0.85

Calls 9

ParseObjectTagsFunction · 0.92
trimEtagFunction · 0.85
parseRFC7231TimeFunction · 0.85
extractObjMetadataFunction · 0.85
amzRestoreToStructFunction · 0.85
ToMapMethod · 0.80
GetMethod · 0.45
KeyMethod · 0.45

Tested by

no test coverage detected