header.go 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. /*
  2. * MinIO Cloud Storage, (C) 2019 MinIO, Inc.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. package s3_constants
  17. import (
  18. "net/http"
  19. "strings"
  20. "github.com/gorilla/mux"
  21. )
  22. // Standard S3 HTTP request constants
  23. const (
  24. // S3 storage class
  25. AmzStorageClass = "x-amz-storage-class"
  26. // S3 user-defined metadata
  27. AmzUserMetaPrefix = "X-Amz-Meta-"
  28. AmzUserMetaDirective = "X-Amz-Metadata-Directive"
  29. AmzUserMetaMtime = "X-Amz-Meta-Mtime"
  30. // S3 object tagging
  31. AmzObjectTagging = "X-Amz-Tagging"
  32. AmzObjectTaggingPrefix = "X-Amz-Tagging-"
  33. AmzObjectTaggingDirective = "X-Amz-Tagging-Directive"
  34. AmzTagCount = "x-amz-tagging-count"
  35. SeaweedFSIsDirectoryKey = "X-Seaweedfs-Is-Directory-Key"
  36. SeaweedFSPartNumber = "X-Seaweedfs-Part-Number"
  37. SeaweedFSUploadId = "X-Seaweedfs-Upload-Id"
  38. // S3 ACL headers
  39. AmzCannedAcl = "X-Amz-Acl"
  40. AmzAclFullControl = "X-Amz-Grant-Full-Control"
  41. AmzAclRead = "X-Amz-Grant-Read"
  42. AmzAclWrite = "X-Amz-Grant-Write"
  43. AmzAclReadAcp = "X-Amz-Grant-Read-Acp"
  44. AmzAclWriteAcp = "X-Amz-Grant-Write-Acp"
  45. // S3 Object Lock headers
  46. AmzBucketObjectLockEnabled = "X-Amz-Bucket-Object-Lock-Enabled"
  47. AmzObjectLockMode = "X-Amz-Object-Lock-Mode"
  48. AmzObjectLockRetainUntilDate = "X-Amz-Object-Lock-Retain-Until-Date"
  49. AmzObjectLockLegalHold = "X-Amz-Object-Lock-Legal-Hold"
  50. // S3 conditional headers
  51. IfMatch = "If-Match"
  52. IfNoneMatch = "If-None-Match"
  53. IfModifiedSince = "If-Modified-Since"
  54. IfUnmodifiedSince = "If-Unmodified-Since"
  55. // S3 conditional copy headers
  56. AmzCopySourceIfMatch = "X-Amz-Copy-Source-If-Match"
  57. AmzCopySourceIfNoneMatch = "X-Amz-Copy-Source-If-None-Match"
  58. AmzCopySourceIfModifiedSince = "X-Amz-Copy-Source-If-Modified-Since"
  59. AmzCopySourceIfUnmodifiedSince = "X-Amz-Copy-Source-If-Unmodified-Since"
  60. AmzMpPartsCount = "X-Amz-Mp-Parts-Count"
  61. // S3 Server-Side Encryption with Customer-provided Keys (SSE-C)
  62. AmzServerSideEncryptionCustomerAlgorithm = "X-Amz-Server-Side-Encryption-Customer-Algorithm"
  63. AmzServerSideEncryptionCustomerKey = "X-Amz-Server-Side-Encryption-Customer-Key"
  64. AmzServerSideEncryptionCustomerKeyMD5 = "X-Amz-Server-Side-Encryption-Customer-Key-MD5"
  65. AmzServerSideEncryptionContext = "X-Amz-Server-Side-Encryption-Context"
  66. // S3 Server-Side Encryption with KMS (SSE-KMS)
  67. AmzServerSideEncryption = "X-Amz-Server-Side-Encryption"
  68. AmzServerSideEncryptionAwsKmsKeyId = "X-Amz-Server-Side-Encryption-Aws-Kms-Key-Id"
  69. AmzServerSideEncryptionBucketKeyEnabled = "X-Amz-Server-Side-Encryption-Bucket-Key-Enabled"
  70. // S3 SSE-C copy source headers
  71. AmzCopySourceServerSideEncryptionCustomerAlgorithm = "X-Amz-Copy-Source-Server-Side-Encryption-Customer-Algorithm"
  72. AmzCopySourceServerSideEncryptionCustomerKey = "X-Amz-Copy-Source-Server-Side-Encryption-Customer-Key"
  73. AmzCopySourceServerSideEncryptionCustomerKeyMD5 = "X-Amz-Copy-Source-Server-Side-Encryption-Customer-Key-MD5"
  74. )
  75. // Metadata keys for internal storage
  76. const (
  77. // SSE-KMS metadata keys
  78. AmzEncryptedDataKey = "x-amz-encrypted-data-key"
  79. AmzEncryptionContextMeta = "x-amz-encryption-context"
  80. // SeaweedFS internal metadata keys for encryption (prefixed to avoid automatic HTTP header conversion)
  81. SeaweedFSSSEKMSKey = "x-seaweedfs-sse-kms-key" // Key for storing serialized SSE-KMS metadata
  82. SeaweedFSSSES3Key = "x-seaweedfs-sse-s3-key" // Key for storing serialized SSE-S3 metadata
  83. SeaweedFSSSEIV = "x-seaweedfs-sse-c-iv" // Key for storing SSE-C IV
  84. // Multipart upload metadata keys for SSE-KMS (consistent with internal metadata key pattern)
  85. SeaweedFSSSEKMSKeyID = "x-seaweedfs-sse-kms-key-id" // Key ID for multipart upload SSE-KMS inheritance
  86. SeaweedFSSSEKMSEncryption = "x-seaweedfs-sse-kms-encryption" // Encryption type for multipart upload SSE-KMS inheritance
  87. SeaweedFSSSEKMSBucketKeyEnabled = "x-seaweedfs-sse-kms-bucket-key-enabled" // Bucket key setting for multipart upload SSE-KMS inheritance
  88. SeaweedFSSSEKMSEncryptionContext = "x-seaweedfs-sse-kms-encryption-context" // Encryption context for multipart upload SSE-KMS inheritance
  89. SeaweedFSSSEKMSBaseIV = "x-seaweedfs-sse-kms-base-iv" // Base IV for multipart upload SSE-KMS (for IV offset calculation)
  90. // Multipart upload metadata keys for SSE-S3
  91. SeaweedFSSSES3Encryption = "x-seaweedfs-sse-s3-encryption" // Encryption type for multipart upload SSE-S3 inheritance
  92. SeaweedFSSSES3BaseIV = "x-seaweedfs-sse-s3-base-iv" // Base IV for multipart upload SSE-S3 (for IV offset calculation)
  93. SeaweedFSSSES3KeyData = "x-seaweedfs-sse-s3-key-data" // Encrypted key data for multipart upload SSE-S3 inheritance
  94. )
  95. // SeaweedFS internal headers for filer communication
  96. const (
  97. SeaweedFSSSEKMSKeyHeader = "X-SeaweedFS-SSE-KMS-Key" // Header for passing SSE-KMS metadata to filer
  98. SeaweedFSSSEIVHeader = "X-SeaweedFS-SSE-IV" // Header for passing SSE-C IV to filer (SSE-C only)
  99. SeaweedFSSSEKMSBaseIVHeader = "X-SeaweedFS-SSE-KMS-Base-IV" // Header for passing base IV for multipart SSE-KMS
  100. SeaweedFSSSES3BaseIVHeader = "X-SeaweedFS-SSE-S3-Base-IV" // Header for passing base IV for multipart SSE-S3
  101. SeaweedFSSSES3KeyDataHeader = "X-SeaweedFS-SSE-S3-Key-Data" // Header for passing key data for multipart SSE-S3
  102. )
  103. // Non-Standard S3 HTTP request constants
  104. const (
  105. AmzIdentityId = "s3-identity-id"
  106. AmzAccountId = "s3-account-id"
  107. AmzAuthType = "s3-auth-type"
  108. )
  109. func GetBucketAndObject(r *http.Request) (bucket, object string) {
  110. vars := mux.Vars(r)
  111. bucket = vars["bucket"]
  112. object = vars["object"]
  113. if !strings.HasPrefix(object, "/") {
  114. object = "/" + object
  115. }
  116. return
  117. }
  118. func GetPrefix(r *http.Request) string {
  119. query := r.URL.Query()
  120. prefix := query.Get("prefix")
  121. if !strings.HasPrefix(prefix, "/") {
  122. prefix = "/" + prefix
  123. }
  124. return prefix
  125. }
  126. var PassThroughHeaders = map[string]string{
  127. "response-cache-control": "Cache-Control",
  128. "response-content-disposition": "Content-Disposition",
  129. "response-content-encoding": "Content-Encoding",
  130. "response-content-language": "Content-Language",
  131. "response-content-type": "Content-Type",
  132. "response-expires": "Expires",
  133. }