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 #pragma once 18 #include <alibabacloud/oss/Export.h> 19 #include <string> 20 #include <list> 21 22 namespace AlibabaCloud 23 { 24 namespace OSS 25 { 26 using CORSAllowedList = std::list<std::string>; 27 class ALIBABACLOUD_OSS_EXPORT CORSRule 28 { 29 public: 30 static const int UNSET_AGE_SEC = -1; 31 public: CORSRule()32 CORSRule() : maxAgeSeconds_(UNSET_AGE_SEC) {} AllowedOrigins()33 const CORSAllowedList& AllowedOrigins() const { return allowedOrigins_; } AllowedMethods()34 const CORSAllowedList& AllowedMethods() const { return allowedMethods_; } AllowedHeaders()35 const CORSAllowedList& AllowedHeaders() const { return allowedHeaders_; } ExposeHeaders()36 const CORSAllowedList& ExposeHeaders() const { return exposeHeaders_; } MaxAgeSeconds()37 int MaxAgeSeconds() const { return maxAgeSeconds_; } addAllowedOrigin(const std::string & origin)38 void addAllowedOrigin(const std::string& origin) { allowedOrigins_.push_back(origin); } addAllowedMethod(const std::string & method)39 void addAllowedMethod(const std::string& method) { allowedMethods_.push_back(method); } addAllowedHeader(const std::string & header)40 void addAllowedHeader(const std::string& header) { allowedHeaders_.push_back(header); } addExposeHeader(const std::string & header)41 void addExposeHeader(const std::string& header) { exposeHeaders_.push_back(header); } setMaxAgeSeconds(int value)42 void setMaxAgeSeconds(int value) { maxAgeSeconds_ = value; } clear()43 void clear() 44 { 45 allowedOrigins_.clear(); 46 allowedMethods_.clear(); 47 allowedHeaders_.clear(); 48 exposeHeaders_.clear(); 49 maxAgeSeconds_ = UNSET_AGE_SEC; 50 } 51 private: 52 CORSAllowedList allowedOrigins_; 53 CORSAllowedList allowedMethods_; 54 CORSAllowedList allowedHeaders_; 55 CORSAllowedList exposeHeaders_; 56 int maxAgeSeconds_; 57 }; 58 59 using CORSRuleList = std::list<CORSRule>; 60 } 61 } 62