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/HeadObjectResult.h>
17#include <aws/core/utils/xml/XmlSerializer.h>
18#include <aws/core/AmazonWebServiceResult.h>
19#include <aws/core/utils/StringUtils.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;
28
29HeadObjectResult::HeadObjectResult() :
30 m_deleteMarker(false),
31 m_contentLength(0),
32 m_missingMeta(0),
33 m_serverSideEncryption(ServerSideEncryption::NOT_SET),
34 m_storageClass(StorageClass::NOT_SET),
35 m_requestCharged(RequestCharged::NOT_SET),
36 m_replicationStatus(ReplicationStatus::NOT_SET),
37 m_partsCount(0),
38 m_objectLockMode(ObjectLockMode::NOT_SET),
39 m_objectLockLegalHoldStatus(ObjectLockLegalHoldStatus::NOT_SET)
40{
41}
42
43HeadObjectResult::HeadObjectResult(const Aws::AmazonWebServiceResult<XmlDocument>& result) :
44 m_deleteMarker(false),
45 m_contentLength(0),
46 m_missingMeta(0),
47 m_serverSideEncryption(ServerSideEncryption::NOT_SET),
48 m_storageClass(StorageClass::NOT_SET),
49 m_requestCharged(RequestCharged::NOT_SET),
50 m_replicationStatus(ReplicationStatus::NOT_SET),
51 m_partsCount(0),
52 m_objectLockMode(ObjectLockMode::NOT_SET),
53 m_objectLockLegalHoldStatus(ObjectLockLegalHoldStatus::NOT_SET)
54{
55 *this = result;
56}
57
58HeadObjectResult& HeadObjectResult::operator =(const Aws::AmazonWebServiceResult<XmlDocument>& result)
59{
60 const XmlDocument& xmlDocument = result.GetPayload();
61 XmlNode resultNode = xmlDocument.GetRootElement();
62
63 if(!resultNode.IsNull())
64 {
65 }
66
67 const auto& headers = result.GetHeaderValueCollection();
68 const auto& deleteMarkerIter = headers.find("x-amz-delete-marker");
69 if(deleteMarkerIter != headers.end())
70 {
71 m_deleteMarker = StringUtils::ConvertToBool(deleteMarkerIter->second.c_str());
72 }
73
74 const auto& acceptRangesIter = headers.find("accept-ranges");
75 if(acceptRangesIter != headers.end())
76 {
77 m_acceptRanges = acceptRangesIter->second;
78 }
79
80 const auto& expirationIter = headers.find("x-amz-expiration");
81 if(expirationIter != headers.end())
82 {
83 m_expiration = expirationIter->second;
84 }
85
86 const auto& restoreIter = headers.find("x-amz-restore");
87 if(restoreIter != headers.end())
88 {
89 m_restore = restoreIter->second;
90 }
91
92 const auto& lastModifiedIter = headers.find("last-modified");
93 if(lastModifiedIter != headers.end())
94 {
95 m_lastModified = DateTime(lastModifiedIter->second, DateFormat::RFC822);
96 }
97
98 const auto& contentLengthIter = headers.find("content-length");
99 if(contentLengthIter != headers.end())
100 {
101 m_contentLength = StringUtils::ConvertToInt64(contentLengthIter->second.c_str());
102 }
103
104 const auto& eTagIter = headers.find("etag");
105 if(eTagIter != headers.end())
106 {
107 m_eTag = eTagIter->second;
108 }
109
110 const auto& missingMetaIter = headers.find("x-amz-missing-meta");
111 if(missingMetaIter != headers.end())
112 {
113 m_missingMeta = StringUtils::ConvertToInt32(missingMetaIter->second.c_str());
114 }
115
116 const auto& versionIdIter = headers.find("x-amz-version-id");
117 if(versionIdIter != headers.end())
118 {
119 m_versionId = versionIdIter->second;
120 }
121
122 const auto& cacheControlIter = headers.find("cache-control");
123 if(cacheControlIter != headers.end())
124 {
125 m_cacheControl = cacheControlIter->second;
126 }
127
128 const auto& contentDispositionIter = headers.find("content-disposition");
129 if(contentDispositionIter != headers.end())
130 {
131 m_contentDisposition = contentDispositionIter->second;
132 }
133
134 const auto& contentEncodingIter = headers.find("content-encoding");
135 if(contentEncodingIter != headers.end())
136 {
137 m_contentEncoding = contentEncodingIter->second;
138 }
139
140 const auto& contentLanguageIter = headers.find("content-language");
141 if(contentLanguageIter != headers.end())
142 {
143 m_contentLanguage = contentLanguageIter->second;
144 }
145
146 const auto& contentTypeIter = headers.find("content-type");
147 if(contentTypeIter != headers.end())
148 {
149 m_contentType = contentTypeIter->second;
150 }
151
152 const auto& expiresIter = headers.find("expires");
153 if(expiresIter != headers.end())
154 {
155 m_expires = DateTime(expiresIter->second, DateFormat::RFC822);
156 }
157
158 const auto& websiteRedirectLocationIter = headers.find("x-amz-website-redirect-location");
159 if(websiteRedirectLocationIter != headers.end())
160 {
161 m_websiteRedirectLocation = websiteRedirectLocationIter->second;
162 }
163
164 const auto& serverSideEncryptionIter = headers.find("x-amz-server-side-encryption");
165 if(serverSideEncryptionIter != headers.end())
166 {
167 m_serverSideEncryption = ServerSideEncryptionMapper::GetServerSideEncryptionForName(serverSideEncryptionIter->second);
168 }
169
170 std::size_t prefixSize = sizeof("x-amz-meta-") - 1; //subtract the NULL terminator out
171 for(const auto& item : headers)
172 {
173 std::size_t foundPrefix = item.first.find("x-amz-meta-");
174
175 if(foundPrefix != std::string::npos)
176 {
177 m_metadata[item.first.substr(prefixSize)] = item.second;
178 }
179 }
180
181 const auto& sSECustomerAlgorithmIter = headers.find("x-amz-server-side-encryption-customer-algorithm");
182 if(sSECustomerAlgorithmIter != headers.end())
183 {
184 m_sSECustomerAlgorithm = sSECustomerAlgorithmIter->second;
185 }
186
187 const auto& sSECustomerKeyMD5Iter = headers.find("x-amz-server-side-encryption-customer-key-md5");
188 if(sSECustomerKeyMD5Iter != headers.end())
189 {
190 m_sSECustomerKeyMD5 = sSECustomerKeyMD5Iter->second;
191 }
192
193 const auto& sSEKMSKeyIdIter = headers.find("x-amz-server-side-encryption-aws-kms-key-id");
194 if(sSEKMSKeyIdIter != headers.end())
195 {
196 m_sSEKMSKeyId = sSEKMSKeyIdIter->second;
197 }
198
199 const auto& storageClassIter = headers.find("x-amz-storage-class");
200 if(storageClassIter != headers.end())
201 {
202 m_storageClass = StorageClassMapper::GetStorageClassForName(storageClassIter->second);
203 }
204
205 const auto& requestChargedIter = headers.find("x-amz-request-charged");
206 if(requestChargedIter != headers.end())
207 {
208 m_requestCharged = RequestChargedMapper::GetRequestChargedForName(requestChargedIter->second);
209 }
210
211 const auto& replicationStatusIter = headers.find("x-amz-replication-status");
212 if(replicationStatusIter != headers.end())
213 {
214 m_replicationStatus = ReplicationStatusMapper::GetReplicationStatusForName(replicationStatusIter->second);
215 }
216
217 const auto& partsCountIter = headers.find("x-amz-mp-parts-count");
218 if(partsCountIter != headers.end())
219 {
220 m_partsCount = StringUtils::ConvertToInt32(partsCountIter->second.c_str());
221 }
222
223 const auto& objectLockModeIter = headers.find("x-amz-object-lock-mode");
224 if(objectLockModeIter != headers.end())
225 {
226 m_objectLockMode = ObjectLockModeMapper::GetObjectLockModeForName(objectLockModeIter->second);
227 }
228
229 const auto& objectLockRetainUntilDateIter = headers.find("x-amz-object-lock-retain-until-date");
230 if(objectLockRetainUntilDateIter != headers.end())
231 {
232 m_objectLockRetainUntilDate = DateTime(objectLockRetainUntilDateIter->second, DateFormat::RFC822);
233 }
234
235 const auto& objectLockLegalHoldStatusIter = headers.find("x-amz-object-lock-legal-hold");
236 if(objectLockLegalHoldStatusIter != headers.end())
237 {
238 m_objectLockLegalHoldStatus = ObjectLockLegalHoldStatusMapper::GetObjectLockLegalHoldStatusForName(objectLockLegalHoldStatusIter->second);
239 }
240
241 return *this;
242}
243