ServiceRequest.cc 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. /*
  2. * Copyright 1999-2019 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. #include <alibabacloud/core/ServiceRequest.h>
  17. #include <alibabacloud/core/AlibabaCloud.h>
  18. namespace AlibabaCloud {
  19. ServiceRequest::ServiceRequest(const std::string &product,
  20. const std::string &version) :
  21. content_(nullptr),
  22. contentSize_(0),
  23. params_(),
  24. product_(product),
  25. resourcePath_("/"),
  26. version_(version),
  27. scheme_("https"),
  28. connectTimeout_(kInvalidTimeout),
  29. readTimeout_(kInvalidTimeout) {
  30. }
  31. ServiceRequest::ServiceRequest(const ServiceRequest &other) :
  32. content_(nullptr),
  33. contentSize_(other.contentSize_),
  34. params_(other.params_),
  35. product_(other.product_),
  36. resourcePath_(other.resourcePath_),
  37. version_(other.version_),
  38. scheme_(other.scheme_),
  39. connectTimeout_(other.connectTimeout_),
  40. readTimeout_(other.readTimeout_) {
  41. setContent(other.content_, other.contentSize_);
  42. }
  43. ServiceRequest::ServiceRequest(ServiceRequest &&other) {
  44. *this = std::move(other);
  45. }
  46. ServiceRequest& ServiceRequest::operator=(const ServiceRequest &other) {
  47. if (this != &other) {
  48. content_ = nullptr;
  49. contentSize_ = 0;
  50. params_ = other.params_;
  51. connectTimeout_ = other.connectTimeout_;
  52. readTimeout_ = other.readTimeout_;
  53. setContent(other.content_, other.contentSize_);
  54. }
  55. return *this;
  56. }
  57. ServiceRequest& ServiceRequest::operator=(ServiceRequest &&other) {
  58. if (this != &other)
  59. *this = std::move(other);
  60. return *this;
  61. }
  62. ServiceRequest::~ServiceRequest() {
  63. if (content_)
  64. delete content_;
  65. }
  66. const char * ServiceRequest::content() const {
  67. return content_;
  68. }
  69. size_t ServiceRequest::contentSize() const {
  70. return contentSize_;
  71. }
  72. bool ServiceRequest::hasContent() const {
  73. return (contentSize_ != 0);
  74. }
  75. void ServiceRequest::setContent(const char * data, size_t size) {
  76. if (content_)
  77. delete content_;
  78. content_ = nullptr;
  79. contentSize_ = 0;
  80. if (size) {
  81. contentSize_ = size;
  82. content_ = new char[size];
  83. std::copy(data, data + size, content_);
  84. }
  85. }
  86. void ServiceRequest::addParameter(const ParameterNameType & name,
  87. const ParameterValueType & value) {
  88. setParameter(name, value);
  89. }
  90. ServiceRequest::ParameterValueType ServiceRequest::parameter(
  91. const ParameterNameType &name)const {
  92. ParameterCollection::const_iterator it = params_.find(name);
  93. if (it == params_.end()) {
  94. return ParameterValueType("");
  95. }
  96. return it->second;
  97. }
  98. ServiceRequest::ParameterValueType ServiceRequest::coreParameter(
  99. const ParameterNameType &name)const {
  100. return parameter(name);
  101. }
  102. ServiceRequest::ParameterCollection ServiceRequest::parameters() const {
  103. return params_;
  104. }
  105. void ServiceRequest::removeParameter(const ParameterNameType & name) {
  106. params_.erase(name);
  107. }
  108. void ServiceRequest::setParameter(const ParameterNameType &name,
  109. const ParameterValueType &value) {
  110. params_[name] = value;
  111. }
  112. void ServiceRequest::setCoreParameter(const ParameterNameType &name,
  113. const ParameterValueType &value) {
  114. setParameter(name, value);
  115. }
  116. void ServiceRequest::setParameters(const ParameterCollection & params) {
  117. params_ = params;
  118. }
  119. std::string ServiceRequest::version()const {
  120. return version_;
  121. }
  122. void ServiceRequest::setVersion(const std::string &version) {
  123. version_ = version;
  124. }
  125. std::string ServiceRequest::product() const {
  126. return product_;
  127. }
  128. void ServiceRequest::setProduct(const std::string & product) {
  129. product_ = product;
  130. }
  131. std::string ServiceRequest::resourcePath() const {
  132. return resourcePath_;
  133. }
  134. void ServiceRequest::setResourcePath(const std::string & path) {
  135. resourcePath_ = path;
  136. }
  137. void ServiceRequest::setScheme(const std::string scheme) {
  138. scheme_ = scheme;
  139. }
  140. std::string ServiceRequest::scheme() const {
  141. return scheme_;
  142. }
  143. long ServiceRequest::connectTimeout() const{
  144. return connectTimeout_;
  145. }
  146. long ServiceRequest::readTimeout() const{
  147. return readTimeout_;
  148. }
  149. void ServiceRequest::setConnectTimeout(const long connectTimeout) {
  150. connectTimeout_ = connectTimeout;
  151. }
  152. void ServiceRequest::setReadTimeout(const long readTimeout) {
  153. readTimeout_ = readTimeout;
  154. }
  155. } // namespace AlibabaCloud