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)
| 273 | // ToObjectInfo converts http header values into ObjectInfo type, |
| 274 | // extracts metadata and fills in all the necessary fields in ObjectInfo. |
| 275 | func 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 | } |
no test coverage detected