CORSRule.h 2.3 KB

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