1/*
2* Copyright 2010-2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
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* A copy of the License is located at
7*
8* http://aws.amazon.com/apache2.0
9*
10* or in the "license" file accompanying this file. This file is distributed
11* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
12* express or implied. See the License for the specific language governing
13* permissions and limitations under the License.
14*/
15
16#include <aws/s3/model/PutObjectRequest.h>
17#include <aws/core/AmazonWebServiceResult.h>
18#include <aws/core/http/URI.h>
19#include <aws/core/utils/memory/stl/AWSStringStream.h>
20#include <aws/core/utils/HashingUtils.h>
21
22#include <utility>
23
24using namespace Aws::S3::Model;
25using namespace Aws::Utils::Stream;
26using namespace Aws::Utils;
27using namespace Aws::Http;
28using namespace Aws;
29
30PutObjectRequest::PutObjectRequest() :
31 m_aCL(ObjectCannedACL::NOT_SET),
32 m_aCLHasBeenSet(false),
33 m_bucketHasBeenSet(false),
34 m_cacheControlHasBeenSet(false),
35 m_contentDispositionHasBeenSet(false),
36 m_contentEncodingHasBeenSet(false),
37 m_contentLanguageHasBeenSet(false),
38 m_contentLength(0),
39 m_contentLengthHasBeenSet(false),
40 m_contentMD5HasBeenSet(false),
41 m_expiresHasBeenSet(false),
42 m_grantFullControlHasBeenSet(false),
43 m_grantReadHasBeenSet(false),
44 m_grantReadACPHasBeenSet(false),
45 m_grantWriteACPHasBeenSet(false),
46 m_keyHasBeenSet(false),
47 m_metadataHasBeenSet(false),
48 m_serverSideEncryption(ServerSideEncryption::NOT_SET),
49 m_serverSideEncryptionHasBeenSet(false),
50 m_storageClass(StorageClass::NOT_SET),
51 m_storageClassHasBeenSet(false),
52 m_websiteRedirectLocationHasBeenSet(false),
53 m_sSECustomerAlgorithmHasBeenSet(false),
54 m_sSECustomerKeyHasBeenSet(false),
55 m_sSECustomerKeyMD5HasBeenSet(false),
56 m_sSEKMSKeyIdHasBeenSet(false),
57 m_sSEKMSEncryptionContextHasBeenSet(false),
58 m_requestPayer(RequestPayer::NOT_SET),
59 m_requestPayerHasBeenSet(false),
60 m_taggingHasBeenSet(false),
61 m_objectLockMode(ObjectLockMode::NOT_SET),
62 m_objectLockModeHasBeenSet(false),
63 m_objectLockRetainUntilDateHasBeenSet(false),
64 m_objectLockLegalHoldStatus(ObjectLockLegalHoldStatus::NOT_SET),
65 m_objectLockLegalHoldStatusHasBeenSet(false),
66 m_customizedAccessLogTagHasBeenSet(false)
67{
68}
69
70
71void PutObjectRequest::AddQueryStringParameters(URI& uri) const
72{
73 Aws::StringStream ss;
74 if(!m_customizedAccessLogTag.empty())
75 {
76 // only accept customized LogTag which starts with "x-"
77 Aws::Map<Aws::String, Aws::String> collectedLogTags;
78 for(const auto& entry: m_customizedAccessLogTag)
79 {
80 if (!entry.first.empty() && !entry.second.empty() && entry.first.substr(0, 2) == "x-")
81 {
82 collectedLogTags.emplace(entry.first, entry.second);
83 }
84 }
85
86 if (!collectedLogTags.empty())
87 {
88 uri.AddQueryStringParameter(collectedLogTags);
89 }
90 }
91}
92Aws::Http::HeaderValueCollection PutObjectRequest::GetRequestSpecificHeaders() const
93{
94 Aws::Http::HeaderValueCollection headers;
95 Aws::StringStream ss;
96 if(m_aCLHasBeenSet)
97 {
98 headers.emplace("x-amz-acl", ObjectCannedACLMapper::GetNameForObjectCannedACL(m_aCL));
99 }
100
101 if(m_cacheControlHasBeenSet)
102 {
103 ss << m_cacheControl;
104 headers.emplace("cache-control", ss.str());
105 ss.str("");
106 }
107
108 if(m_contentDispositionHasBeenSet)
109 {
110 ss << m_contentDisposition;
111 headers.emplace("content-disposition", ss.str());
112 ss.str("");
113 }
114
115 if(m_contentEncodingHasBeenSet)
116 {
117 ss << m_contentEncoding;
118 headers.emplace("content-encoding", ss.str());
119 ss.str("");
120 }
121
122 if(m_contentLanguageHasBeenSet)
123 {
124 ss << m_contentLanguage;
125 headers.emplace("content-language", ss.str());
126 ss.str("");
127 }
128
129 if(m_contentLengthHasBeenSet)
130 {
131 ss << m_contentLength;
132 headers.emplace("content-length", ss.str());
133 ss.str("");
134 }
135
136 if(m_contentMD5HasBeenSet)
137 {
138 ss << m_contentMD5;
139 headers.emplace("content-md5", ss.str());
140 ss.str("");
141 }
142
143 if(m_expiresHasBeenSet)
144 {
145 headers.emplace("expires", m_expires.ToGmtString(DateFormat::RFC822));
146 }
147
148 if(m_grantFullControlHasBeenSet)
149 {
150 ss << m_grantFullControl;
151 headers.emplace("x-amz-grant-full-control", ss.str());
152 ss.str("");
153 }
154
155 if(m_grantReadHasBeenSet)
156 {
157 ss << m_grantRead;
158 headers.emplace("x-amz-grant-read", ss.str());
159 ss.str("");
160 }
161
162 if(m_grantReadACPHasBeenSet)
163 {
164 ss << m_grantReadACP;
165 headers.emplace("x-amz-grant-read-acp", ss.str());
166 ss.str("");
167 }
168
169 if(m_grantWriteACPHasBeenSet)
170 {
171 ss << m_grantWriteACP;
172 headers.emplace("x-amz-grant-write-acp", ss.str());
173 ss.str("");
174 }
175
176 if(m_metadataHasBeenSet)
177 {
178 for(const auto& item : m_metadata)
179 {
180 ss << "x-amz-meta-" << item.first;
181 headers.emplace(ss.str(), item.second);
182 ss.str("");
183 }
184 }
185
186 if(m_serverSideEncryptionHasBeenSet)
187 {
188 headers.emplace("x-amz-server-side-encryption", ServerSideEncryptionMapper::GetNameForServerSideEncryption(m_serverSideEncryption));
189 }
190
191 if(m_storageClassHasBeenSet)
192 {
193 headers.emplace("x-amz-storage-class", StorageClassMapper::GetNameForStorageClass(m_storageClass));
194 }
195
196 if(m_websiteRedirectLocationHasBeenSet)
197 {
198 ss << m_websiteRedirectLocation;
199 headers.emplace("x-amz-website-redirect-location", ss.str());
200 ss.str("");
201 }
202
203 if(m_sSECustomerAlgorithmHasBeenSet)
204 {
205 ss << m_sSECustomerAlgorithm;
206 headers.emplace("x-amz-server-side-encryption-customer-algorithm", ss.str());
207 ss.str("");
208 }
209
210 if(m_sSECustomerKeyHasBeenSet)
211 {
212 ss << m_sSECustomerKey;
213 headers.emplace("x-amz-server-side-encryption-customer-key", ss.str());
214 ss.str("");
215 }
216
217 if(m_sSECustomerKeyMD5HasBeenSet)
218 {
219 ss << m_sSECustomerKeyMD5;
220 headers.emplace("x-amz-server-side-encryption-customer-key-md5", ss.str());
221 ss.str("");
222 }
223
224 if(m_sSEKMSKeyIdHasBeenSet)
225 {
226 ss << m_sSEKMSKeyId;
227 headers.emplace("x-amz-server-side-encryption-aws-kms-key-id", ss.str());
228 ss.str("");
229 }
230
231 if(m_sSEKMSEncryptionContextHasBeenSet)
232 {
233 ss << m_sSEKMSEncryptionContext;
234 headers.emplace("x-amz-server-side-encryption-context", ss.str());
235 ss.str("");
236 }
237
238 if(m_requestPayerHasBeenSet)
239 {
240 headers.emplace("x-amz-request-payer", RequestPayerMapper::GetNameForRequestPayer(m_requestPayer));
241 }
242
243 if(m_taggingHasBeenSet)
244 {
245 ss << m_tagging;
246 headers.emplace("x-amz-tagging", ss.str());
247 ss.str("");
248 }
249
250 if(m_objectLockModeHasBeenSet)
251 {
252 headers.emplace("x-amz-object-lock-mode", ObjectLockModeMapper::GetNameForObjectLockMode(m_objectLockMode));
253 }
254
255 if(m_objectLockRetainUntilDateHasBeenSet)
256 {
257 headers.emplace("x-amz-object-lock-retain-until-date", m_objectLockRetainUntilDate.ToGmtString(DateFormat::RFC822));
258 }
259
260 if(m_objectLockLegalHoldStatusHasBeenSet)
261 {
262 headers.emplace("x-amz-object-lock-legal-hold", ObjectLockLegalHoldStatusMapper::GetNameForObjectLockLegalHoldStatus(m_objectLockLegalHoldStatus));
263 }
264
265 return headers;
266
267}
268