1 /*
2 * Copyright 2009-2017 Alibaba Cloud 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 * 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
17
18 #include <alibabacloud/oss/model/GeneratePresignedUrlRequest.h>
19 #include <alibabacloud/oss/http/HttpType.h>
20 #include "utils/Utils.h"
21 #include <sstream>
22 #include <chrono>
23 using namespace AlibabaCloud::OSS;
24
GeneratePresignedUrlRequest(const std::string & bucket,const std::string & key)25 GeneratePresignedUrlRequest::GeneratePresignedUrlRequest(const std::string &bucket, const std::string &key) :
26 GeneratePresignedUrlRequest(bucket, key, Http::Method::Get)
27 {
28 }
29
GeneratePresignedUrlRequest(const std::string & bucket,const std::string & key,Http::Method method)30 GeneratePresignedUrlRequest::GeneratePresignedUrlRequest(const std::string &bucket, const std::string &key, Http::Method method):
31 bucket_(bucket),
32 key_(key),
33 method_(method)
34 {
35 //defalt 15 min
36 std::time_t t = std::time(nullptr) + 15*60;
37 metaData_.setExpirationTime(std::to_string(t));
38 }
39
setBucket(const std::string & bucket)40 void GeneratePresignedUrlRequest::setBucket(const std::string &bucket)
41 {
42 bucket_ = bucket;
43 }
44
setKey(const std::string & key)45 void GeneratePresignedUrlRequest::setKey(const std::string &key)
46 {
47 key_ = key;
48 }
49
setContentType(const std::string & value)50 void GeneratePresignedUrlRequest::setContentType(const std::string &value)
51 {
52 metaData_.HttpMetaData()[Http::CONTENT_TYPE] = value;
53 }
54
setContentMd5(const std::string & value)55 void GeneratePresignedUrlRequest::setContentMd5(const std::string &value)
56 {
57 metaData_.HttpMetaData()[Http::CONTENT_MD5] = value;
58 }
59
setExpires(int64_t unixTime)60 void GeneratePresignedUrlRequest::setExpires(int64_t unixTime)
61 {
62 metaData_.setExpirationTime(std::to_string(unixTime));
63 }
64
setProcess(const std::string & value)65 void GeneratePresignedUrlRequest::setProcess(const std::string &value)
66 {
67 parameters_["x-oss-process"] = value;
68 }
69
setTrafficLimit(uint64_t value)70 void GeneratePresignedUrlRequest::setTrafficLimit(uint64_t value)
71 {
72 parameters_["x-oss-traffic-limit"] = std::to_string(value);
73 }
74
setVersionId(const std::string & versionId)75 void GeneratePresignedUrlRequest::setVersionId(const std::string& versionId)
76 {
77 parameters_["versionId"] = versionId;
78 }
79
setRequestPayer(RequestPayer value)80 void GeneratePresignedUrlRequest::setRequestPayer(RequestPayer value)
81 {
82 if (value == RequestPayer::Requester) {
83 parameters_["x-oss-request-payer"] = ToLower(ToRequestPayerName(value));
84 }
85 }
86
addResponseHeaders(RequestResponseHeader header,const std::string & value)87 void GeneratePresignedUrlRequest::addResponseHeaders(RequestResponseHeader header, const std::string &value)
88 {
89 static const char *ResponseHeader[] = {
90 "response-content-type", "response-content-language",
91 "response-expires", "response-cache-control",
92 "response-content-disposition", "response-content-encoding" };
93 parameters_[ResponseHeader[header - RequestResponseHeader::ContentType]] = value;
94 }
95
addParameter(const std::string & key,const std::string & value)96 void GeneratePresignedUrlRequest::addParameter(const std::string&key, const std::string &value)
97 {
98 parameters_[key] = value;
99 }
100
UserMetaData()101 MetaData &GeneratePresignedUrlRequest::UserMetaData()
102 {
103 return metaData_.UserMetaData();
104 }
105