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 #include <alibabacloud/oss/model/SetBucketRefererRequest.h>
18 #include <sstream>
19 
20 using namespace AlibabaCloud::OSS;
21 
SetBucketRefererRequest(const std::string & bucket)22 SetBucketRefererRequest::SetBucketRefererRequest(const std::string& bucket) :
23     OssBucketRequest(bucket),
24     allowEmptyReferer_(true)
25 {
26     setFlags(Flags() | REQUEST_FLAG_CONTENTMD5);
27 }
28 
SetBucketRefererRequest(const std::string & bucket,const RefererList & refererList)29 SetBucketRefererRequest::SetBucketRefererRequest(const std::string& bucket, const RefererList& refererList) :
30     SetBucketRefererRequest(bucket, refererList, true)
31 {
32 }
33 
SetBucketRefererRequest(const std::string & bucket,const RefererList & refererList,bool allowEmptyReferer)34 SetBucketRefererRequest::SetBucketRefererRequest(const std::string& bucket, const RefererList& refererList,
35     bool allowEmptyReferer) :
36     OssBucketRequest(bucket),
37     allowEmptyReferer_(allowEmptyReferer),
38     refererList_(refererList)
39 {
40     setFlags(Flags() | REQUEST_FLAG_CONTENTMD5);
41 }
42 
payload() const43 std::string SetBucketRefererRequest::payload() const
44 {
45     std::stringstream ss;
46     ss << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" << std::endl;
47     ss << "<RefererConfiguration>" << std::endl;
48     ss << "  <AllowEmptyReferer>" << (allowEmptyReferer_ ? "true" : "false") << "</AllowEmptyReferer>" << std::endl;
49     ss << "  <RefererList>" << std::endl;
50     for (const auto &referer : refererList_) {
51         ss << "    <Referer>" << referer << "</Referer>" << std::endl;
52     }
53     ss << "  </RefererList>" << std::endl;
54     ss << "</RefererConfiguration>" << std::endl;
55     return ss.str();
56 }
specialParameters() const57 ParameterCollection SetBucketRefererRequest::specialParameters() const
58 {
59     ParameterCollection parameters;
60     parameters["referer"] = "";
61     return parameters;
62 }
63