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/CopyObjectRequest.h>
17#include <aws/core/utils/xml/XmlSerializer.h>
18#include <aws/core/utils/memory/stl/AWSStringStream.h>
19#include <aws/core/http/URI.h>
20#include <aws/core/utils/memory/stl/AWSStringStream.h>
21
22#include <utility>
23
24using namespace Aws::S3::Model;
25using namespace Aws::Utils::Xml;
26using namespace Aws::Utils;
27using namespace Aws::Http;
28
29CopyObjectRequest::CopyObjectRequest() :
30 m_aCL(ObjectCannedACL::NOT_SET),
31 m_aCLHasBeenSet(false),
32 m_bucketHasBeenSet(false),
33 m_cacheControlHasBeenSet(false),
34 m_contentDispositionHasBeenSet(false),
35 m_contentEncodingHasBeenSet(false),
36 m_contentLanguageHasBeenSet(false),
37 m_contentTypeHasBeenSet(false),
38 m_copySourceHasBeenSet(false),
39 m_copySourceIfMatchHasBeenSet(false),
40 m_copySourceIfModifiedSinceHasBeenSet(false),
41 m_copySourceIfNoneMatchHasBeenSet(false),
42 m_copySourceIfUnmodifiedSinceHasBeenSet(false),
43 m_expiresHasBeenSet(false),
44 m_grantFullControlHasBeenSet(false),
45 m_grantReadHasBeenSet(false),
46 m_grantReadACPHasBeenSet(false),
47 m_grantWriteACPHasBeenSet(false),
48 m_keyHasBeenSet(false),
49 m_metadataHasBeenSet(false),
50 m_metadataDirective(MetadataDirective::NOT_SET),
51 m_metadataDirectiveHasBeenSet(false),
52 m_taggingDirective(TaggingDirective::NOT_SET),
53 m_taggingDirectiveHasBeenSet(false),
54 m_serverSideEncryption(ServerSideEncryption::NOT_SET),
55 m_serverSideEncryptionHasBeenSet(false),
56 m_storageClass(StorageClass::NOT_SET),
57 m_storageClassHasBeenSet(false),
58 m_websiteRedirectLocationHasBeenSet(false),
59 m_sSECustomerAlgorithmHasBeenSet(false),
60 m_sSECustomerKeyHasBeenSet(false),
61 m_sSECustomerKeyMD5HasBeenSet(false),
62 m_sSEKMSKeyIdHasBeenSet(false),
63 m_sSEKMSEncryptionContextHasBeenSet(false),
64 m_copySourceSSECustomerAlgorithmHasBeenSet(false),
65 m_copySourceSSECustomerKeyHasBeenSet(false),
66 m_copySourceSSECustomerKeyMD5HasBeenSet(false),
67 m_requestPayer(RequestPayer::NOT_SET),
68 m_requestPayerHasBeenSet(false),
69 m_taggingHasBeenSet(false),
70 m_objectLockMode(ObjectLockMode::NOT_SET),
71 m_objectLockModeHasBeenSet(false),
72 m_objectLockRetainUntilDateHasBeenSet(false),
73 m_objectLockLegalHoldStatus(ObjectLockLegalHoldStatus::NOT_SET),
74 m_objectLockLegalHoldStatusHasBeenSet(false),
75 m_customizedAccessLogTagHasBeenSet(false)
76{
77}
78
79Aws::String CopyObjectRequest::SerializePayload() const
80{
81 return {};
82}
83
84void CopyObjectRequest::AddQueryStringParameters(URI& uri) const
85{
86 Aws::StringStream ss;
87 if(!m_customizedAccessLogTag.empty())
88 {
89 // only accept customized LogTag which starts with "x-"
90 Aws::Map<Aws::String, Aws::String> collectedLogTags;
91 for(const auto& entry: m_customizedAccessLogTag)
92 {
93 if (!entry.first.empty() && !entry.second.empty() && entry.first.substr(0, 2) == "x-")
94 {
95 collectedLogTags.emplace(entry.first, entry.second);
96 }
97 }
98
99 if (!collectedLogTags.empty())
100 {
101 uri.AddQueryStringParameter(collectedLogTags);
102 }
103 }
104}
105
106Aws::Http::HeaderValueCollection CopyObjectRequest::GetRequestSpecificHeaders() const
107{
108 Aws::Http::HeaderValueCollection headers;
109 Aws::StringStream ss;
110 if(m_aCLHasBeenSet)
111 {
112 headers.emplace("x-amz-acl", ObjectCannedACLMapper::GetNameForObjectCannedACL(m_aCL));
113 }
114
115 if(m_cacheControlHasBeenSet)
116 {
117 ss << m_cacheControl;
118 headers.emplace("cache-control", ss.str());
119 ss.str("");
120 }
121
122 if(m_contentDispositionHasBeenSet)
123 {
124 ss << m_contentDisposition;
125 headers.emplace("content-disposition", ss.str());
126 ss.str("");
127 }
128
129 if(m_contentEncodingHasBeenSet)
130 {
131 ss << m_contentEncoding;
132 headers.emplace("content-encoding", ss.str());
133 ss.str("");
134 }
135
136 if(m_contentLanguageHasBeenSet)
137 {
138 ss << m_contentLanguage;
139 headers.emplace("content-language", ss.str());
140 ss.str("");
141 }
142
143 if(m_contentTypeHasBeenSet)
144 {
145 ss << m_contentType;
146 headers.emplace("content-type", ss.str());
147 ss.str("");
148 }
149
150 if(m_copySourceHasBeenSet)
151 {
152 ss << m_copySource;
153 headers.emplace("x-amz-copy-source", URI::URLEncodePath(ss.str()));
154 ss.str("");
155 }
156
157 if(m_copySourceIfMatchHasBeenSet)
158 {
159 ss << m_copySourceIfMatch;
160 headers.emplace("x-amz-copy-source-if-match", ss.str());
161 ss.str("");
162 }
163
164 if(m_copySourceIfModifiedSinceHasBeenSet)
165 {
166 headers.emplace("x-amz-copy-source-if-modified-since", m_copySourceIfModifiedSince.ToGmtString(DateFormat::RFC822));
167 }
168
169 if(m_copySourceIfNoneMatchHasBeenSet)
170 {
171 ss << m_copySourceIfNoneMatch;
172 headers.emplace("x-amz-copy-source-if-none-match", ss.str());
173 ss.str("");
174 }
175
176 if(m_copySourceIfUnmodifiedSinceHasBeenSet)
177 {
178 headers.emplace("x-amz-copy-source-if-unmodified-since", m_copySourceIfUnmodifiedSince.ToGmtString(DateFormat::RFC822));
179 }
180
181 if(m_expiresHasBeenSet)
182 {
183 headers.emplace("expires", m_expires.ToGmtString(DateFormat::RFC822));
184 }
185
186 if(m_grantFullControlHasBeenSet)
187 {
188 ss << m_grantFullControl;
189 headers.emplace("x-amz-grant-full-control", ss.str());
190 ss.str("");
191 }
192
193 if(m_grantReadHasBeenSet)
194 {
195 ss << m_grantRead;
196 headers.emplace("x-amz-grant-read", ss.str());
197 ss.str("");
198 }
199
200 if(m_grantReadACPHasBeenSet)
201 {
202 ss << m_grantReadACP;
203 headers.emplace("x-amz-grant-read-acp", ss.str());
204 ss.str("");
205 }
206
207 if(m_grantWriteACPHasBeenSet)
208 {
209 ss << m_grantWriteACP;
210 headers.emplace("x-amz-grant-write-acp", ss.str());
211 ss.str("");
212 }
213
214 if(m_metadataHasBeenSet)
215 {
216 for(const auto& item : m_metadata)
217 {
218 ss << "x-amz-meta-" << item.first;
219 headers.emplace(ss.str(), item.second);
220 ss.str("");
221 }
222 }
223
224 if(m_metadataDirectiveHasBeenSet)
225 {
226 headers.emplace("x-amz-metadata-directive", MetadataDirectiveMapper::GetNameForMetadataDirective(m_metadataDirective));
227 }
228
229 if(m_taggingDirectiveHasBeenSet)
230 {
231 headers.emplace("x-amz-tagging-directive", TaggingDirectiveMapper::GetNameForTaggingDirective(m_taggingDirective));
232 }
233
234 if(m_serverSideEncryptionHasBeenSet)
235 {
236 headers.emplace("x-amz-server-side-encryption", ServerSideEncryptionMapper::GetNameForServerSideEncryption(m_serverSideEncryption));
237 }
238
239 if(m_storageClassHasBeenSet)
240 {
241 headers.emplace("x-amz-storage-class", StorageClassMapper::GetNameForStorageClass(m_storageClass));
242 }
243
244 if(m_websiteRedirectLocationHasBeenSet)
245 {
246 ss << m_websiteRedirectLocation;
247 headers.emplace("x-amz-website-redirect-location", ss.str());
248 ss.str("");
249 }
250
251 if(m_sSECustomerAlgorithmHasBeenSet)
252 {
253 ss << m_sSECustomerAlgorithm;
254 headers.emplace("x-amz-server-side-encryption-customer-algorithm", ss.str());
255 ss.str("");
256 }
257
258 if(m_sSECustomerKeyHasBeenSet)
259 {
260 ss << m_sSECustomerKey;
261 headers.emplace("x-amz-server-side-encryption-customer-key", ss.str());
262 ss.str("");
263 }
264
265 if(m_sSECustomerKeyMD5HasBeenSet)
266 {
267 ss << m_sSECustomerKeyMD5;
268 headers.emplace("x-amz-server-side-encryption-customer-key-md5", ss.str());
269 ss.str("");
270 }
271
272 if(m_sSEKMSKeyIdHasBeenSet)
273 {
274 ss << m_sSEKMSKeyId;
275 headers.emplace("x-amz-server-side-encryption-aws-kms-key-id", ss.str());
276 ss.str("");
277 }
278
279 if(m_sSEKMSEncryptionContextHasBeenSet)
280 {
281 ss << m_sSEKMSEncryptionContext;
282 headers.emplace("x-amz-server-side-encryption-context", ss.str());
283 ss.str("");
284 }
285
286 if(m_copySourceSSECustomerAlgorithmHasBeenSet)
287 {
288 ss << m_copySourceSSECustomerAlgorithm;
289 headers.emplace("x-amz-copy-source-server-side-encryption-customer-algorithm", ss.str());
290 ss.str("");
291 }
292
293 if(m_copySourceSSECustomerKeyHasBeenSet)
294 {
295 ss << m_copySourceSSECustomerKey;
296 headers.emplace("x-amz-copy-source-server-side-encryption-customer-key", ss.str());
297 ss.str("");
298 }
299
300 if(m_copySourceSSECustomerKeyMD5HasBeenSet)
301 {
302 ss << m_copySourceSSECustomerKeyMD5;
303 headers.emplace("x-amz-copy-source-server-side-encryption-customer-key-md5", ss.str());
304 ss.str("");
305 }
306
307 if(m_requestPayerHasBeenSet)
308 {
309 headers.emplace("x-amz-request-payer", RequestPayerMapper::GetNameForRequestPayer(m_requestPayer));
310 }
311
312 if(m_taggingHasBeenSet)
313 {
314 ss << m_tagging;
315 headers.emplace("x-amz-tagging", ss.str());
316 ss.str("");
317 }
318
319 if(m_objectLockModeHasBeenSet)
320 {
321 headers.emplace("x-amz-object-lock-mode", ObjectLockModeMapper::GetNameForObjectLockMode(m_objectLockMode));
322 }
323
324 if(m_objectLockRetainUntilDateHasBeenSet)
325 {
326 headers.emplace("x-amz-object-lock-retain-until-date", m_objectLockRetainUntilDate.ToGmtString(DateFormat::RFC822));
327 }
328
329 if(m_objectLockLegalHoldStatusHasBeenSet)
330 {
331 headers.emplace("x-amz-object-lock-legal-hold", ObjectLockLegalHoldStatusMapper::GetNameForObjectLockLegalHoldStatus(m_objectLockLegalHoldStatus));
332 }
333
334 return headers;
335}
336